Recently, I worked for a company that uses Salesforce CRM to manage its business. While working, I was given the responsibility to display the shipping price of the product based on the customer’s and the warehouse’s location.
As a solution, I discovered the GEOLOCATION() function. Let’s go into more detail and learn how to use Salesforce.
In this tutorial, we will learn about the GEOLOCATION() function in Salesforce and how to use it to calculate geolocation based on latitude and longitude.
Moreover, we will focus on the syntax of the Salesforce GEOLOCATION() function and some practical examples for implementation.
What is the GEOLOCATION() Function in Salesforce?
There are various mathematical functions in Salesforce for performing calculations, including GEOLOCATION().
This GEOLOCATION() function returns geolocation values. It is also used to return geolocation based on latitude and longitude values. In addition, make sure this GEOLOCATION() function is used with Salesforce’s DISTANCE() function.
Moreover, keep one thing in mind: this GEOLOCATION() function only supports the “GeoLocation” data type.
Syntax and Usage of the GEOLOCATION() Function in Salesforce
Below is the syntax for the GEOLOCATION() function in Salesforce:
GEOLOCATION(latitude, longitude)Here, we have two parameters as follows:
- Latitude: This parameter specifies the geolocation’s latitude. It takes the value as a number, field, or formula.
- Longitude: This parameter specifies the geolocation’s longitude. The parameter value can be a field, a constant, or a complex formula.
To deeply understand this concept, let’s see a Salesforce example:
As discussed above, I was tasked with displaying the shipping price for the product based on the customer’s distance from the warehouse. To do this, I will use the GEOLOCATION() and DISTANCE() functions in Salesforce.
Here is the formula:
IF(
DISTANCE(Coustmer_Location__c, GEOLOCATION(Warehouse_Location__c), 'km') > 500,
1000,
0
)With this, we have understood the GEOLOCATION() function, its syntax, and one real-life usage example. Now, we will move on to learn how to use the GEOLOCATION() function in Salesforce.
Use the GEOLOCATION() Function in Salesforce
- Log in to Salesforce org, then click on the “Gear Icon” located in the top right corner of the page. To proceed, select “Setup“ from the dropdown menu.

- From the menu’s left side, click on “Object Manager”.

- Now, search for the object for which you want to use the GEOLOCATION() function in the search bar. To track the campaign location, I look up the “Campaign” object in this example.
- Click the “Campaign” object to redirect to the campaign page.

- From the menu on the left-hand side of the page, click on “Field and Relationship“.
- To create a formula field that uses the GEOLOCATION() function, click the “New” button.

- Now, it redirects to the “Choose the field type” page. Here, select the “Formula” as the data type by checking the radio button next to it.
- To proceed, click on the “Next” button.

- After entering the “Field Label” for the formula, the “Field Name” will be automatically filled in. In this instance, I entered “Campaign Location” as the field label.
- Select the “Data Type“ for the field on which we want to apply the GEOLOCATION() function. In this case, I chose “Number” as the formula’s return type and set its “Decimal Value” to 2.
- Click on the “Next” button to proceed to the next step.

- To compute “Campaign Location” by using the GEOLOCATION() formula, enter the formula in the advanced formula editor. The formula is as follows:
DISTANCE(Client_Location__c, GEOLOCATION(Venue_Location_Latitude__s, Venue_Location_Longitude__s), 'km')- In this formula, the DISTANCE() function is used to find the distance between the client location “Client_Location__c”.
- Next, the GEOLOCATION() function is used to get the latitude and longitude value of the venue location “Venue_Location_Latitude__s” and “Venue_Location_Longitude__s” respectively.
- Finally, the formula returns the distance between the client and venue locations in kilometres.
- To make sure that there is no mistake in the formula, click on the “Check Syntax” button.
- Optionally, we may define the “Description”, “Help Text”, and as well as “Handle the empty field” if you like.
- To continue, click on the “Next” button.

- Select the appropriate “Field Level Security“ option. In this case, I have selected the “Visible” checkbox as I want it to be visible to everyone. Then click the “Next” button in the menu.

- Now, choose the “Page Layout“ that will display your content. To save the advanced formula field, click on the “Save” button.

- We can use the formula field once it’s created. Let’s look at an example:
- Open the Campaigns Tab and create a new campaign with the fields “Venue_Location_Latitude__s”, “Client_Location__c” and “Venue_Location_Longitude__s“.
- After that, click on the Details section, and here the “Campaign Location” field appears, which shows you the result of the GEOLOCATION() function.

As a result, we now know how to use the GEOLOCATION() function in Salesforce.
Conclusion
In a nutshell, we have learned about the GEOLOCATION() function in Salesforce with its syntax and real-life examples. In addition, we learned the steps to calculate the geolocation based on latitude and longitude values in Salesforce Lightning and Salesforce Classic.
You may also like:
- LOG() Function in Salesforce
- EXP() Function in Salesforce
- Distance() Function in Salesforce
- COS() Function in Salesforce
- Salesforce DAYOYEAR Function
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.