Monday, May 4, 2015

Salesforce Summer 15 New Feature || Now we can use Location and Distance Variables in SOQL and SOSL Queries

With Salesforce Summer'15 release, now we can use location and distance variable in SOQL and SOSL queries.

To know more about location and distance variable, I will request to check Salesforce's documentation @

Location-Based SOQL Queries

Now let me explain this new feature with a small code snippet.
In my account object, I have created one custom field of type Geolocation with name Head Office Location (API Name: Head_Office_Location__c).

Below is the code snippet -
As you can see in the above code what I am trying to find all the accounts whose head office is located within 1 miles from my current location. To achieve this, I have used my current location's latitude and longitude as apex bind variable in SOQL query.

The way DISTANCE and GEOLOCATION function work are given below -
  • DISTANCE(mylocation1mylocation2, 'unit')
  • GEOLOCATION(latitudelongitude)
Now after Summer'15, you can replace any of the parameters used in the above two functions by apex bind variable.

So to me, it is really a good feature. What do you guys think? Please provide your feedback. Thanks.


  1. I think you've got a little bug in your example: DISTANCE(...) > 1 should be DISTANCE(...) < 1 as you've said that these are HQ within 1 mile.

    1. Yes, you are correct. Thanks for letting me know. I have updated the code snippet.