Wednesday, April 3, 2013

Using the new Salesforce Geolocation Fields

I started with all the links I could find on Google
https://help.salesforce.com/HTSearchResults?qry=geolocation+soql
https://help.salesforce.com/HTViewSolution?id=000159817&language=en_US
https://help.salesforce.com/HTViewSolution?id=000171328&language=en_US
http://salesforce.stackexchange.com/questions/388/geolocation-searching
http://blogs.developerforce.com/engineering/2012/06/new-geolocation-features-and-mobile-apps.html

The best sample query I could find was from that last link:
SELECT name__c, phone__c
FROM restaurant__c
WHERE DISTANCE(loc__c, GEOLOCATION(37.794915,-122.394733), "mi") <= 1


 But the above did not work.  Problem?  As documented elsewhere the query only supports < or > not <=.  The correct query is:

SELECT name__c, phone__c
FROM restaurant__c
WHERE DISTANCE(loc__c, GEOLOCATION(37.794915,-122.394733), "mi") < 1



Another link that shows the correct query was found later. See
http://www.salesforce.com/us/developer/docs/soql_sosl/

Testing Queries


Next I found that my copy of SOQLExplorer doesn't support these queries at all.   I'll have to update my MAC operating system to update to the latest SOQLExplore.   But we can test these queries using the developer console.   Log onto Salesforce. Select your Name. In the drop down select Developer Console.

In the console use the Query Editor.

Using Geolocation with Partner API Queries

Next I found that my older version of the partner API does not support these queries either.  That made me try to rebuild the partner.api.  See previous posting
http://sforcehacks.blogspot.ca/2013/04/building-partnerjar-api-file.html

I'll see if this works and then come back and update this posting.

No comments:

Post a Comment