Salesforce Maps Apex Developer Guide
Summer '25 preview (API version 64.0)
Spring '25 (API version 63.0)
Winter '25 (API version 62.0)
Summer '24 (API version 61.0)
Spring '24 (API version 60.0)
Winter '24 (API version 59.0)
Summer '23 (API version 58.0)
Spring '23 (API version 57.0)
Winter '23 (API version 56.0)
Summer '22 (API version 55.0)
Spring '22 (API version 54.0)
Winter '22 (API version 53.0)
Summer '21 (API version 52.0)
No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Overview
Requirements
Assign Records to Owners Using an Assignment Plan
Create a Route
Create Routes for Specific Users
Create Routes from Visit Plan
Get a Route
Get the Boundary Information
Get the Distance Matrix
Get the Geographical Coordinates of an Address
Get the Geographical Coordinates of Addresses in Batch
Permanently Delete Datasets and Alignments
Retrieve Data That Salesforce Maps Hosts
Retrieve the Geographical Data of Country-Specific Shapes
Retrieve the Geographical Data of Polygons
Retrieve the Territories in Which the Records Reside
Salesforce Maps Apex Methods
Apex is a typed, object-oriented programming language that allows developers to execute
flow and transaction control statements on the Salesforce Platform server, in conjunction with
calls to the API. Use the sample code in this Apex method documentation as a starting point for
your Salesforce Maps implementation.
-
Assign Records to Owners Using an Assignment Plan
The AssignRecords() Apex method assigns records to users automatically using rules specified in an assignment plan. For example, suppose that you use a web-to-lead generation form to generate inbound leads in Salesforce. You use the AssignRecords() method to assign those leads to sales reps as soon as the lead records are created, reducing the time for sales reps to contact leads. -
Create a Route
The CreateRoute() Apex method creates a record that includes a list of waypoints that reps access in Salesforce Maps. The record doesn't include a route between waypoints. -
Create Routes for Specific Users
The StartAdvancedOptimizationForUsers() Apex method creates routes for users assigned to any active Salesforce Maps Advanced visit plan. Use this method to leverage Salesforce Maps Advanced visit planning from your custom workflow or app, such as a retail execution app. By using Apex, you can generate routes for reps automatically without having to make field reps click through the UI to manually generate routes. -
Create Routes from Visit Plan
The StartAdvancedOptimizationForVisitPlan() Apex method creates routes for all users assigned to a Salesforce Maps Advanced visit plan. Use this method to leverage Salesforce Maps Advanced visit planning from your custom workflow or app, such as a retail execution app. By using Apex, you can generate routes for reps automatically without having to make field reps click through the UI to manually generate routes. -
Get a Route
The getRoute() Apex method returns a route between two or more waypoints for the specified mode of transportation. The travel time depends on the mode of transportation. The route appears in Salesforce Maps for the users who requested the route, such as a delivery truck driver and the admin. This method doesn’t optimize the route. Instead, it finds a route between the waypoints in entered sequence. -
Get the Boundary Information
The GetBoundaryInformation() Apex method returns geographical IDs of locations that fit the specified search criteria. -
Get the Distance Matrix
The GetDistanceMatrix() Apex method takes a set of locations and returns the estimated travel distance in meters and the time in seconds between the locations. -
Get the Geographical Coordinates of an Address
The Geocode() Apex method takes a single address and returns the geographical coordinates and the formatted address. -
Get the Geographical Coordinates of Addresses in Batch
The BatchGeocode() Apex method takes addresses and returns their geographical coordinates and formatted addresses. -
Permanently Delete Datasets and Alignments
The DoCleanup() Apex method permanently removes, or cleans up, datasets and related alignments that a user already deleted using Territory Planning Data Sets or Territory Planning Alignments | Delete in the UI. Use this method to reduce object size and improve Territory Planning load time and performance. -
Retrieve Data That Salesforce Maps Hosts
The GetHostedData() Apex method retrieves geographical IDs for properties and displays them in Salesforce Maps. We accomplish this retrieval in two requests while using the same method. The first request returns geographical IDs for properties that Salesforce Maps hosts for a specified area and filter criteria. The second request takes these geographical IDs and display parameters, such as legend and popup information, and displays them in Salesforce Maps. -
Retrieve the Geographical Data of Country-Specific Shapes
The GetBoundaryGeoJSON() Apex method returns the geographical data, area, and perimeter for a list of geographical IDs. -
Retrieve the Geographical Data of Polygons
The getPolygonGeometry() Apex method returns the geometric data, such as the area and perimeter, for the requested geographical shape or custom polygon. -
Retrieve the Territories in Which the Records Reside
The PointInPolygon() Apex method returns the territory shape in which each record resides. It reads in the geographical coordinates of one or more records and compares each against the surrounding territory shape. Review Considerations for Retrieving Territory Shapes.