Newer Version Available
Create Routes from Visit Plan
The StartAdvancedOptimizationForVisitPlan() Apex method is the equivalent of clicking Plan Visits on an active visit plan in Maps Advanced Visit Plans.
When you use this method, only the user’s future shifts are included for planning visits along the route. If a user’s shift has started or is within 2 hours of starting at the time the method runs, the method doesn’t change visit appointments for today’s date. In that case, one day is added to the starting date (startDate).
Visits are created from startDate through a visit plan’s end date.
Signature
- maps is the namespace that's available after you install Salesforce Maps.
- API is the class that contains the global methods exposed to developers.
- StartAdvancedOptimizationForVisitPlan() is the method.
- templateId is the Salesforce record id of a visit plan.
- startDate is optional. If not specified, the method uses today’s date as the date to start planning visits. If startDate occurs during a user’s shift or within 2 hours of the user’s next shift, then one day is added to the specified startDate.
Sample Code
Example
Sample Response
This method returns an Apex Map<String, Object> object that contains a boolean flag indicating whether the routes were created successfully.