Wednesday, April 3, 2013

Using the new Salesforce Geolocation Fields

I started with all the links I could find on Google

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

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

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

Building the Partner.jar API file

The SF documentation is missing some information needed to build the latest partner.jar API file.  Here is the link I found that gets you started

The missing part is a dependency on a Javascript libraray called rhino.  If you follow the instructions given you get

~/Documents/workspace2/salesforce/carmanah_salesforce$ java -classpath force-wsc-27.0.0.jar partner.wsdl partner-27.jar
[WSC][]Created temp dir: /var/folders/D0/D0me7a5vFGmGh95S1IO9PU+++TI/-Tmp-/wsdlc-temp-3884699697501788635-dir
[WSC][wsdlc.<init>:81]Generating Java files from schema ...
Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/javascript/Scriptable
Caused by: java.lang.ClassNotFoundException: org.mozilla.javascript.Scriptable
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    ... 6 more

The solution is to get the latest rhino library from
and add this to the command line.

Just for the record, the WSC download is here
I'm working with v27 today,  file: "force-wsc-27.0.0.jar"
I also downloaded rhino jar file: "js-1.7R2.jar"

I am working on a MAC. I placed both downloaded jar files in my working directory.  I downloaded the partner.wsdl file as well.  Then use this command line to produce the partner jar file:

java -classpath force-wsc-27.0.0.jar:js-1.7R2.jar partner.wsdl partner-27.jar

On some systems you need to use a semi-colon to separate the jar files. Like this:
java -classpath force-wsc-27.0.0.jar;js-1.7R2.jar partner.wsdl partner-27.jar