top of page

SOQL Queries

Retrieve records with locations saved in geolocation or address fields as individual latitude and longitude values by appending “__latitude__s” or “__longitude__s” to the field name, instead of the usual “__c”. For example:

SELECT Name, Location__latitude__s, Location__longitude__s

FROM Warehouse__c

SOQL executed using the SOAP or REST APIs can SELECT the compound field, instead of the individual elements. Compound fields are returned as structured data rather than primitive values. For example:

SELECT Name, Location__c

FROM Warehouse__c


This query retrieves the same data as the previous query, but the Location__c field is a compound geolocation field, and the results combine the two primitive values. Here are sample results from a REST API request.


{

"totalSize" : 10,

"done" : true,

"records" : [ {

"attributes" : {

"type" : "Warehouse__c",

"url" : "/services/data/v30.0/sobjects/Warehouse__c/a06D00000017O4nIAE"

},

"Name" : "Ferry Building Depot",

"Location__c" : {

"latitude" : 37.79302,

"longitude" : -122.394507

}

}, {

"attributes" : {

"type" : "Warehouse__c",

"url" : "/services/data/v30.0/sobjects/Warehouse__c/a06D00000017O4oIAE"

},

"Name" : "Aloha Warehouse",

"Location__c" : {

"latitude" : 37.786108,

"longitude" : -122.430152

}

},

...

]

}



Retrieve records with locations within or outside of a certain radius with distance conditions in the WHERE clause of the query. To construct an appropriate distance condition, use the following functions.


SELECT Name, Location__c

FROM Warehouse__c

WHERE DISTANCE(Location__c, GEOLOCATION(37.775,-122.418), 'mi') < 20





Recent Posts

See All
Writing dynamic soql

Dynamic SOQL refers to the creation of a SOQL string at run time with Apex code. Dynamic SOQL enables you to create more...

 
 
 

Comments


Post: Blog2_Post

©2020 by SalesforceDemystified. Proudly created with Wix.com

bottom of page