ScheduleService Class
Namespace
Usage
This class calls the scheduling engine and schedules the given service appointment in the highest-scoring available slot.
- SLR or point-to-point predictive travel is the selected routing, and
- Results aren’t stored in the local cache
ScheduleService Methods
ScheduleService includes the following static methods.
schedule(policy, serviceId)
Signature
public static FSL.ScheduleResult schedule(Id policy, Id serviceId)
Parameters
Return Value
Type: FSL.ScheduleResult
Usage
This method schedules the service appointment in the best available slot. If there are no available slots, the appointment isn’t scheduled. This method can be called with only one service appointment at a time. To schedule multiple service appointments, use an Apex batch class. Call this method in batches of one.
If you are using the schedule method with the appointment booking method, perform a time zone conversion. The results of appointment booking are returned in the time zone specified in the method signature. Convert these values back to UTC.
Example
// FSL.ScheduleService class
// The Schedule method returns a ScheduleResult result
FSL.ScheduleResult myResult = new FSL.ScheduleResult();
// static FSL.ScheduleResult Schedule(Scheduling Policy ID, Service Appointment ID)
myResult = FSL.ScheduleService.schedule(Scheduling Policy ID,Service Appointment ID);
System.debug(myResult);
scheduleExtended(policy, serviceId)
Signature
public static List<FSL.ScheduleResult> scheduleExtended(Id policy, Id serviceId)
Parameters
Return Value
Type: List<FSL.ScheduleResult>
Usage
Use this method to schedule two service appointments in a complex work chain. This method respects the complex work setting Use all-or-none scheduling for related appointments. If there are no available slots, appointments in the complex work chain aren’t scheduled.
The scheduleExtended method is valid for a chain of two appointments; if the appointment in serviceId has dependencies with more than one other appointment, scheduling results can be different than expected.
This method can be called with only one service appointment at a time, and runs asynchronously. To examine results that the asynchronous method returns, use the streaming API and subscribe to MstCompletedChannel, the channel for the Field Service managed package.
If Enhanced Scheduling and Optimization (ESO) is enabled:
- The method runs synchronously.
- The method always uses the ESO behavior, which is all-or-none for related appointments scheduling of complex work.
- The method is valid for a chain of up to five to appointments.
If you’re using the scheduleExtended method with the appointment booking method, perform a time zone conversion. The results of appointment booking are returned in the time zone specified in the method signature. Convert these values back to UTC.
getAppointmentInsights
Signature
public static List<FSL.AppointmentInsightsResult> getAppointmentInsights(Id policyId, Id serviceAppointmentId))
Parameters
Return Value
Example
The following code sample uses the getAppointmentInsights method to return an AppointmentInsightsResult class that provides details about a specific service appointment that can’t be scheduled on the Gantt.
// FSL.ScheduleService class
// The getAppointmentInsights method returns a AppointmentInsightsResult result
FSL.AppointmentInsightsResult myresult = new FSL.AppointmentInsightsResult();
// static FSL.AppointmentInsightsResult
myresult = FSL.ScheduleService.getAppointmentInsights(Scheduling Policy ID,Service Appointment ID);
System.debug(myresult);