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.

Where,

  • maps is the namespace that’s available after you install Salesforce Maps.
  • API is the class that contains the global methods exposed to developers.
  • getRoute() is the method.

This code finds a route for someone driving a car from one grocery store to another.

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.

Input Format of the Request JSON String

The input format supports standard and custom drive profiles. If your drivers require routes optimized for vehicles other than standard cars, create a custom drive profile first, and then add it to your driveProfile string.

Example

Although the return value is an Apex Map<String, Object> object, this JSON response illustrates the essential data you receive in the resulting map.