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
-
Salesforce 2025 Game-Changing Trends You Need to Know28 Jan 2025 Blog
-
Agentforce 2.0: Everything You Need to Know About the Latest Update22 Jan 2025 Blog
-
The Ultimate Guide to NetSuite Development: Tools and Techniques10 Jan 2025 Blog
-
How Salesforce Nonprofit Cloud Transforms Fundraising Strategies10 Jan 2025 Blog
-
The Impact of Salesforce Development Partners on Small and Medium Businesses08 Jan 2025 Blog
-
Key Questions to Ask When Hiring a NetSuite Development Partner08 Jan 2025 Blog
-
Salesforce Agentforce Demystified: Your Essential Guide08 Jan 2025 Blog
-
Salesforce and NetSuite Integration: Driving Business Efficiency with Precision06 Jan 2025 Blog
-
Everest Group has positioned Mirketa as an Aspirant in the report24 Dec 2024 Press Release
-
Salesforce Einstein20 Dec 2024 E-Book
-
Order to Cash Cycle with NetSuite20 Dec 2024 E-Book
-
Empower Your Marketing Strategy with Salesforce Marketing Cloud's Automation Studio Activities13 Dec 2024 Blog
-
Salesforce CPQ for Subscription-based Businesses10 Dec 2024 Blog
-
Unleashing the Magic of Einstein Prediction Builder10 Dec 2024 Blog
-
Customized Templates and Branding with Salesforce Experience Cloud10 Dec 2024 Blog
-
Unleashing the Power of Real- Time Reports and Dashboards in NPSP10 Dec 2024 Blog
-
Top 4 Salesforce Automation Tools in 202409 Dec 2024 Blog
-
Salesforce Service Cloud Implementation: The Ultimate Guide09 Dec 2024 Blog
-
Salesforce CRM Implementation Partner Enhancing Automation in Healthcare09 Dec 2024 Blog
-
Shorten Your Sales Cycle in 8 Steps: Salesforce CPQ Implementation Guide09 Dec 2024 Blog
Categories
Featured by



