While it may seem that including DISTANCE in the SELECT clause (as in Option B) lets you "get the distance" as a return value, the core supported use cases in SOQL for these functions are for filtering and ordering.
A: To filter results based on distance from a latitude and longitude → You can use WHERE clauses to filter records based on distance.
B: To get the distance results from a latitude and longitude → The DISTANCE function returns the calculated distance in miles or kilometers.
Option C is not correct because it says “To order results by distance from a latitude or longitude”. This implies that you can order results by distance from either a latitude or a longitude, but not both. However, the DISTANCE function requires both a latitude and a longitude to calculate the distance from a location. Therefore, you cannot order results by distance from a latitude or longitude, but only from a latitude and longitude pair.
Just to add, I think you can only get the location but not the distance this way.
SELECT Name, Location__latitude__s, Location__longitude__s
FROM Warehouse__c
SELECT Name, StreetAddress__c
FROM Warehouse__c
WHERE DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'mi') < 20
ORDER BY DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'mi')
LIMIT 10
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
rodmfpwc
Highly Voted 4 years, 3 months agovancika
Most Recent 1 month agoBrainMelt12
1 month, 2 weeks agobeardAnt
7 months agomoitam
1 year, 8 months agocode_breaker_27
1 year, 7 months agolorenac2
2 years, 4 months agoLiquad
3 years, 7 months ago