maps is the namespace that’s available after you install Salesforce Maps.
API is the class that contains the global methods exposed to developers.
GetBoundaryGeoJSON() is the method.
Sample Code
This code takes two geographical IDs and returns their total and individual geometric data, area, and perimeter.
If you invoke methods within a flow, process builder, or trigger, avoid uncommitted work errors when you perform one of the following.
Call the methods through a future method
Call the methods as queueable
Uncommitted work errors can also arise if calling out to Salesforce Maps methods more than one time in a single transaction and the Salesforce Maps token hasn’t refreshed in the last 24 hours. If these errors occur, separate each callout into individual transactions.
Different processes refresh the token, such as plotting a route or schedule. The refresh process is almost immediate after each qualifying action occurs.
Warning
Input Format of the Parameters
A list of geographical IDs with the format {countrycode}-{level}-{id}.
A Boolean that determines whether the returned information of the shape is merged (true) or separated (false).
Example
1// Create a list of geographical IDs and set the shape merging parameter.2List<String>geoIds = new List<String>{'CAN-5-24360123', 'CAN-5-24360125'};3Boolean mergeShape = false;45// Call the GetBoundaryGeoJSON() method with the geographical IDs and shape merging parameter.6Map<String, Object>response = maps.API.GetBoundaryGeoJSON(geoIds, mergeShape);78// Log the resulting boundary.9system.debug(response);
Sample Response
Although the return value is an Apex Map<String, Object> object, this JSON response illustrates the essential data you receive in the resulting map.
1{2 "total": {3 "perimeter": 76052.889956049, // Total length in meters of all boundary perimeters.4 "area": 92743880.3549741 // Total area in square meters inside of all boundaries.5 },6 "unit": "meters",7 "geometries": {8 "CAN-5-24360125": {9 "perimeter": 64556.086852368, // Length in meters of the boundary perimeter.10 "area": 88393467.4191344 // Area in square meters inside the boundary.11 },12 "CAN-5-24360123": {13 "perimeter": 11496.803103681,14 "area": 4350412.9358396815 }16 },17 "count": 2,18 "custom": false19}