+ Start a Discussion
ericmonteericmonte 

Simple Geolocation query Error

So im trying to figure out how to query Contacts for a specific distance and I was looking into the documenation to create a sample query in the Developer Console.

 

I created a new field called Location__c under Contact, i set the a contact record with following Lat and Long.

 

And I tried runnign the query editior in developer console:

 

SELECT Name FROM Contact WHERE DISTANCE(Location__c, GEOLOCATION(37.7945391,-122.3947166), "mi") < 1

 

and i get the following error:

Unknown error parsing query

 

 

Also tried running the schema builder off the Eclipse IDE and i get a different errors stating:

Malformed Query -  GEOLOCATION(37.7945391,-122.3947166

 

and it goes on saying error on line 1:91 no viable alternative ""

 

Any help would be great.

 

BTW i was following the instructions from here the

 

http://www.salesforce.com/us/developer/docs/soql_sosl/salesforce_soql_sosl.pdf

http://blogs.developerforce.com/developer-relations/2012/10/winter-13-using-apex-and-soql-with-geolocation.html

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
joshbirkjoshbirk

It wants single quotes:

 

SELECT Name FROM Contact WHERE DISTANCE(Location__c, GEOLOCATION(37.7945391,-122.3947166), 'mi') < 1

 

I'll update the blog post to be more specific.

All Answers

joshbirkjoshbirk

It wants single quotes:

 

SELECT Name FROM Contact WHERE DISTANCE(Location__c, GEOLOCATION(37.7945391,-122.3947166), 'mi') < 1

 

I'll update the blog post to be more specific.

This was selected as the best answer
ericmonteericmonte

oh wow!! i thought I was going crazy! thanks for the quick and prompt response! and btw the BLOG was very helpful!!!!=)