The geolocation custom field allows you to identify locations by their latitude and longitude and to calculate distances between locations.
Available in: both Salesforce Classic and Lightning Experience
Available in: All Editions
You can calculate the distance between two geolocation fields, such as between a warehouse and a store. Or you can calculate the distance between a geolocation field and a pair of latitude and longitude coordinates, such as between a warehouse and 37.794016°, -122.395016°—the location also known as San Francisco. Latitude values must be within -90 and 90. Longitude values must be within -180 and 180.
Geolocation is a compound field that counts toward your org’s limits as three custom fields: one for latitude, one for longitude, and one for internal use. Support for the compound field (geolocation) versus the field’s components (latitude and longitude) varies depending on the functionality you’re using in Salesforce. For example, you can create list views that show the field and its components, but you can’t select the compound geolocation field in Apex. You can run SOQL queries only on a geolocation field’s components.
Compound fields, including geolocation fields, have the following limitations.
Compound fields are read-only. To update field values, modify the individual field components.
Compound fields are accessible only through the SOAP and REST APIs. The compound versions of fields aren’t accessible anywhere in the Salesforce user interface.
Although compound fields can be queried with the Location and Address
Apex classes, they’re editable only as components of the actual field. Read and set geolocation field components by appending “__latitude__s” or “__longitude__s” to the field name, instead of the usual “__c.” For example:
You can’t use compound fields in Visualforce—for example, in an <apex:outputField>. To access or update field values, use the individual field components.
If you select compound fields for export in the Data Loader, they cause error messages. To export values, use individual field components.
Geolocation fields and latitude and longitude on standard addresses aren’t supported in the Data Import Wizard. Use the SOAP or REST APIs to import these fields. If you don’t have a preferred tool for working with Salesforce
APIs, Workbench is an easy way to get started.
Custom geolocation and location fields on standard addresses aren’t supported with email templates.
You can’t use compound fields in lookup filters, except to filter distances that are within or not within given ranges. You can use distance lookup filters only in the Metadata API.
The only formula functions that you can use with compound fields are ISBLANK, ISCHANGED, and ISNULL. You can’t use BLANKVALUE, CASE, NULLVALUE, PRIORVALUE, or the equality and comparison operators with compound fields. The equality and comparison operators include = and == (equal), <> and != (not equal), < (less than), > (greater than), <= (less than or equal), >= (greater than or equal), && (AND), and || (OR).
Other limitations of geolocation fields include:
Geolocation fields aren’t supported in custom settings.
Geolocation fields aren’t available in dashboards or Schema Builder.
Geolocation fields are available in Visual Workflow and in formula-based workflow and approvals, but they can’t be used in filter-based workflow updates and approvals.
DISTANCE formulas are supported in:
Entry criteria for workflow rules and approval processes
Field update actions in workflow rules and approval processes
Custom validation rules
Lookup filters (in the Metadata API only)
Geolocation fields and latitude and longitude on standard addresses aren’t supported in Salesforce to Salesforce.
In Developer, Professional, Enterprise, Unlimited, and Performance editions, Salesforce can automatically add or update geolocation fields for Account, Contact, Lead, and WorkOrder records. To use this feature, your administrator must enable the geo clean rule for each object. For all other objects and editions, set values for latitude and longitude by using SOQL, Workbench, SOAP or REST API, or a geocoding service. You can then use address fields as locatable values. To find geocoding services, search the AppExchange.
Geolocation fields are supported in SOQL with the following limitations.
DISTANCE and GEOLOCATION are supported in WHERE and ORDER BY clauses in SOQL, but not in GROUP BY. DISTANCE is supported in SELECT clauses.
DISTANCE supports only the logical operators > and <, returning values within (<) or beyond (>) a specified radius.
When using the GEOLOCATION function in SOQL queries, the geolocation field must precede the latitude and longitude coordinates. For example, DISTANCE(warehouse_location__c, GEOLOCATION(37.775,-122.418), 'km') works but DISTANCE(GEOLOCATION(37.775,-122.418), warehouse_location__c, 'km') doesn’t work.
Apex bind variables aren’t supported for the units parameter in DISTANCE or GEOLOCATION functions. This query doesn’t work.
String units = 'mi';
List<Account> accountList =
[SELECT ID, Name, BillingLatitude, BillingLongitude
WHERE DISTANCE(My_Location_Field__c, GEOLOCATION(10,10), :units) < 10];