SALESFORCE GEOLOCATION DATA
Author
October 18, 2019
Dealing with data in a location friendly manner is not a new problem. Way past, when Apex was, however, a brand new language and lacked some higher mathematical functions like sine and cosine Trying to determine location without things like sine and cosine was technically not possible. So that was three things that salesforce lacked. One solution can be to tag data based on a database that could translate ZIP codes into latitude and longitude and then do queries based on squares. Because when you don’t have trig on your side, squares are much easier to deal with.
Although it was too hectic as a task, it was also kind of fun.
But now after Winter ’13, you can get even more awesome without the hackery.
Salesforce Objects with Geolocation
The first thing you’ll need to do as a new custom field to your object. Go to the object definition in Setup, and click New Custom Field. After Winter ’13, you’ll see a new field type – Geolocation.Currently, you will be unable to feature Geolocation fields via Schema Builder. One of the choices you’ll need to make is whether you will want the field to be defined in degree or decimal notation. Personally, I realize decimal is used much when using most geolocation services and is overall easier to store. Apex will also refer to the value with decimal notation regardless, so this decision is mostly about how it will be represented externally and you’ll need to determine the number of decimal places to extend your field with regardless. More decimal places mean much greater accuracy, with six decimal places equalling to about 1 meter of accuracy:
Data search based on Location
A geolocation search query :
SELECT Name FROM Contact WHERE DISTANCE(Location__c, GEOLOCATION(37.7945391,-122.3947166), ‘mi’) < 1
That SOQL statement can do the distance calculation and return our one contact within a mile for the coordinates as asked in the query (One Market Street in San Francisco):If I reverse the query that lesser than over to a greater than, we get everyone outside of a mile from
Salesforce HQ, namely:
Geolocation with Apex and Visualforce
What if we want to update this programmatically? Or if you have a database of existing geolocation data based on ZIP code? Most HTML5 friendly browsers support geolocation via JavaScript, therefore, it’d simply be a matter of extending some basic Visualforce with that particular bit of functionality. The trick here is knowing the syntax for the latitude and longitude fields, which goes:
Custom_Field__Latitude__s and Custom_Field__Longitude__
Note the multiple uses of double underlines after the custom field name. So in our case, Contact.Location__c_Latitude__s would refer specifically to the Latitude portion of our Location field.
Geolocation with API
If I sent this POST data via REST to create a new record:
{ “Name” : “Geo”, “FirstName” : “Neo”, “Location__Latitude__s” : 37.794539,
“Location__Longitude__s” : -122.394717 }
The record would be created with the Location fields filled out. Or if I wanted to search,
I could send this over GET:
/services/data/v26.0/query?q=SELECT+Name+FROM+Contact+WHERE+DISTANCE(L ocation__c,+GEOLOCATION(37.7945391,-122.3947166),+’mi’)+<+1
Pranshu Goyal, Director of Products at Mirekta, states: “We envision DSM to be used by every small to a medium-sized organization dealing with bad data and want to get rid of duplicates easily with no cost. We have faced issues dealing with duplicates in our organization. That inspired us to make a solution that is not only simple to use but can be used widely to make the organization’s data clean to make them more efficient and productive. We want DSM to be a solution for every organization looking for duplicate management capability better than the Salesforce out-of-the-box solution with no additional cost.”
Recent Posts
-
The Hybrid Advantage in Salesforce QA20 May 2026 Blog -
CI/CD in Salesforce: Role of QA in DevOps Pipeline19 May 2026 Blog -
Reasons Why Addiction Treatment Centers should consider leveraging Salesforce as a CRM18 May 2026 Blog -
Insights on employee engagement15 May 2026 Blog -
AI Governance Why Businesses Need an AI Strategy Before Implementing AI14 May 2026 Blog -
Salesforce Agentforce: Revolutionizing AI with Autonomous Agents13 May 2026 Blog -
Salesforce Headless 360 Guide | Mirketa13 May 2026 Blog -
Salesforce Custom Permissions12 May 2026 Blog -
Salesforce Education Cloud – Time is Now11 May 2026 Blog -
Top Salesforce Performance Optimization Techniques for Large Enterprises08 May 2026 Blog -
AI Orchestration for Enterprises: Scale Smarter, Faster, and Securely08 May 2026 E-Book -
Stress is always on a vacation @ Mirketa08 May 2026 Blog -
UiPath RPA with AI Capabilities in Salesforce07 May 2026 Blog -
The ROI of AI in Enterprise Applications06 May 2026 Blog -
Rethinking Enterprise Quoting in Salesforce28 Apr 2026 Blog -
Integration Testing with Data Warehouse27 Apr 2026 Blog -
Salesforce Nonprofit Cloud vs NPSP: 2026 Comparison Guide24 Apr 2026 Blog -
Top Use Cases of Salesforce Experience Cloud for Businesses23 Apr 2026 Blog -
How Salesforce Nonprofit Cloud is Transforming Fundraising, Grant Management & CRM in 202622 Apr 2026 Blog -
Get Proactive with Salesforce-Mirketa’s Vaccine Cloud Solutions19 Apr 2026 Blog