Location-Based SOQL Queries

The DISTANCE function is now supported with location-based queries. You can calculate the distance between two location values, such as between a warehouse and a store.

DISTANCE() now works with location and address fields. You can retrieve a specific distance (say, of a store from a contact’s location) and display it to the user.

For example:

SELECT Id, Name, Location, DISTANCE(Location, GEOLOCATION(latitude, longitude), ‘mi’) FROM CONTACT;SELECT Name, BillingCity, BillingState, BillingCountry, BillingLatitude, BillingLongitude FROM Account WHERE DISTANCE(BillingAddress, GEOLOCATION(37.79340, -122.39420), ‘mi’) < 50 LIMIT 20

With custom development, geocodes can unlock a whole new way to understand your customers and run your business. Here are some cool use cases that could be solved using geocodes:

  • Manage and assign territories with precision
  • Show mobile users nearby customers and prospects
  • Plot customers on a map to identify white space
  • Segment customers by location
  • Micro-target leads for events, email campaigns, etc.
  • Track and log mileage
  • Create location-based tasks (“Remind me at a location”)

Leave a Reply

Your email address will not be published. Required fields are marked *