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
:) :) :) :) :):) :) :) :) :) 

Geolocation query error

I am making visualforce with custom controller with find the nearest distance contact from selected contacts using (https://www.salesforce.com.com?id=16digit_contactID)

String q = 'SELECT Name FROM Contact WHERE DISTANCE(Location__c, GEOLOCATION('+String.valueOf(lat)+','+String.valueOf(log)+'), "mi") < 10';
List<Contact> contacts = Database.query(q);

 

Error: no viable alternative at character ' " " '

dmchengdmcheng

The documentation is wrong.  the units value (miles / km) has to be surrounded by single quotes, not double quotes.

 

String qry = 'select Name from Person__c where DISTANCE(Location__c, GEOLOCATION(' + lat + ',' + lng + '), \'mi\') < 100';