You need to sign in to do that
Don't have an account?
Rocks_SFDC
Syntax Issue in SOQL Query by using DISTANCE and GEOLOCATION Function
Hi Team,
I have read in forums that:
DISTANCE(warehouse_location__c, GEOLOCATION(37.775,-122.418), “km”) works.
but DISTANCE(GEOLOCATION(37.775,-122.418), warehouse_location__c, “km”) doesn’t work.
Is the following syntax works?
DISTANCE(GEOLOCATION(Location1__latitude__s,Location1__longitude__s),GEOLOCATION(37.775,-122.418), 'mi')
Please let me know if you have any suggestions on this !!!!
Thanks,
Anil
Hi,
If we go by the book - "Syntax is restricted when running SOQL queries: When using the GEOLOCATION function, the geolocation field must precede the latitude and longitude coordinates. "
Your query should work :
DISTANCE(GEOLOCATION(Location1__latitude__s,Location1__longitude__s),GEOLOCATION(37.775,-122.418), 'mi')
As the location field precedes the coordinates in the above.
Hi Sonam,
Thank you very much for your reply.
I have executed the following query in developer console.
List<Account> Acclist=[Select Location1__latitude__s, Location1__longitude__s from Account where DISTANCE(GEOLOCATION(Location1__latitude__s,Location1__longitude__s),GEOLOCATION(37.775,-122.418), 'mi')<20];
i am getting the following error.
expecting a right parentheses, found ','
Could you please let me know how we can remove above error?
Thanks,
Anil
you will use this code , this is right Syntex
Distance(Geolocation__c,GeoLocation(:latitude,:longitude),'mi')
' mi ' means miles and u will also use ' km ' km means kilometer
Geolocation__c is a Addres types field