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
-
XML Parsing: Using MINIDOM Vs Element Tree (etree) in Python02 Jul 2025 Blog
-
A step by step Guide to create Salesforce web-to-lead form30 Jun 2025 Blog
-
How AI is Transforming User Experience Design in 202526 Jun 2025 Blog
-
How a Salesforce NPSP Consultant Can Elevate Nonprofit Impact25 Jun 2025 Blog
-
Salesforce Load and Performance Testing: Essentials, Importance & Execution23 Jun 2025 Blog
-
Salesforce Website Integration Boost Leads, Automation & Customer Experience11 Jun 2025 Blog
-
Driving Results in Manufacturing with Salesforce Manufacturing Cloud11 Jun 2025 Blog
-
Accelerating Growth with NetSuite SuiteCommerce02 Jun 2025 Blog
-
Salesforce Service Cloud Services streamlining operations29 May 2025 Blog
-
AI for Nonprofits: Mirketa & Exec Precision Webinar27 May 2025 Press Release
-
AI for Nonprofits: Use Cases, Tools & Implementation Strategies20 May 2025 Webinar
-
Javascript Frameworks for Salesforce Lightning Design System18 May 2025 Blog
-
Building a Smart Campus with Salesforce Student Information System: A Road to Smarter Education16 May 2025 Blog
-
Salesforce Nonprofit Cloud: Benefits & Consultant Role15 May 2025 Blog
-
Salesforce Consulting for Nonprofits: Maximize Impact09 May 2025 Blog
-
What to Expect from a Salesforce Admin Service Provider09 May 2025 Blog
-
Maximizing Efficiency with Salesforce Cloud Integration Services09 May 2025 Blog
-
Step-by-Step Guide to Salesforce NPSP Implementation09 May 2025 Blog
-
A Guide on How to Use Salesforce Agentforce for Manufacturing02 May 2025 E-Book
-
Choosing the Right Salesforce Integration Partner: A Complete Guide22 Apr 2025 Blog
Categories
Featured by



