DISTANCE
For more details check SOQL API - DISTANCE.
NOTE! 🚨 All examples use inline queries built with the SOQL Lib Query Builder. If you are using a selector, replace
SOQL.of(...)withYourSelectorName.query().
FILTER​
SOQL
Traditional SOQL
SELECT Id
FROM Contact
WHERE DISTANCE(MailingAddress, GEOLOCATION(72.0,-136.0), 'mi') < 5
SOQL Lib
SOQL Lib Approach
SOQL.of(Contact.SObjectType)
.whereAre(
SOQL.filter.with(
SOQL.distance.of(Contact.MailingAddress)
.between(72.0, -136.0)
.mi()
).lessThan(5)
)
.toList();
ORDERING​
SOQL
Traditional SOQL
SELECT Id
FROM Contact
ORDER BY DISTANCE(MailingAddress, GEOLOCATION(72.0,-136.0), 'mi')
SOQL Lib
SOQL Lib Approach
SOQL.of(Contact.SObjectType)
.orderBy(
SOQL.distance.of(Contact.MailingAddress)
.between(72.0, -136.0)
.mi()
)
.toList();