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.