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

by Sudipta Deb | May 4, 2015 | Apex, Salesforce Release, SOQL, SOSL, Summer15 | 2 comments

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(mylocation1, mylocation2, ‘unit’)
  • GEOLOCATION(latitude, longitude)
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.

Written by

Related Posts

New Apex Method | Extracting Picklist Values Based on Record Type Inside Apex

New Apex Method | Extracting Picklist Values Based on Record Type Inside Apex

For years, Salesforce developers have faced a common challenge: programmatically retrieving picklist values that are specific to a certain Record Type directly within Apex. The “solutions” often involved either complex SOQL queries against metadata, relying on the UI API (with its associated callout limits and serialization overhead), or maintaining clunky custom metadata/settings.

Good news, Technical Potpourri readers! The Salesforce Spring ’26 release is bringing a game-changer that will significantly simplify your Apex code and improve performance: native Apex methods to filter picklist values by Record Type!

read more...
Apex Cursor and Its Advantages Over Batch Processing

Apex Cursor and Its Advantages Over Batch Processing

Struggling with large datasets and SOQL governor limits in Salesforce? In this video, I will dive deep into Apex Cursors, the powerful new feature that revolutionizes how we process millions of records.

Apex Cursors allow developers to navigate through query results in manageable chunks within a single transaction or across Queueable jobs. In this video, I will show you the correct way to implement Apex Cursor and also when this is an exception, how to handle that and perform retry.

read more...

2 Comments

  1. Unknown

    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.

    Reply
  2. Sudipta Deb

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

    Reply

Leave a Reply