function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rocks_SFDCRocks_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

 

Sonam_SFDCSonam_SFDC

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.

 

 

Rocks_SFDCRocks_SFDC

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

 

 

Ashish Kumar 28897Ashish Kumar 28897
Hi Rocks_SFDC

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