GradeSlotsService Class

Represents the results shown in the Candidates quick action. Use the GradeSlotsService class to evaluate all possible slots where a given service appointment can be scheduled.

Namespace

FSL

Usage

When scheduling a service appointment, the user scheduling the appointment must have one of four managed package permission sets: Field Service Admin, Field Service Dispatcher, Field Service Agent, Self-Service. If you’re using platform events to schedule appointments, you must explicitly configure the user so that the user has the correct permissions. Without the proper configuration, the platform event runs as the Automated Process system user and doesn’t have the correct permissions to schedule an appointment. To learn more, see Configure the User and Batch Size for Your Platform Event Trigger.

Note

GradeSlotsService Constructors

The following are constructors for GradeSlotsService.

GradeSlotsService(schedulingPolicyId, serviceAppointmentId)

Creates a new instance of the GradeSlotsService class using the specified scheduling policy ID and service appointment ID.

Signature

public GradeSlotsService(Id schedulingPolicyId, Id serviceAppointmentId)

Parameters

schedulingPolicyId
Type: Id
The record ID of the scheduling policy being used to schedule the service appointment.
serviceAppointmentId
Type: Id
The record ID of the service appointment being scheduled.

GradeSlotsService Methods

GradeSlotsService includes the following static method.

getGradedMatrix(i_ResultsInUserTimeZone)

Returns a matrix of resource IDs and graded time slots. The information is similar to that shown in the Candidates quick action.

Signature

public FSL.AdvancedGapMatrix getGradedMatrix(Boolean i_ResultsInUserTimeZone)

Parameters

i_ResultsInUserTimeZone
Type: Boolean

If true, all DateTimes are returned in the user’s time zone. If false, all DateTimes are returned in UTC.

Return Value

Type: FSL.AdvancedGapMatrix

Usage

If Enhanced Scheduling and Optimization (ESO) is enabled, this method runs synchronously. If ESO isn’t enabled, 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.

Example

This example illustrates how to parse the results in the FSL.AdvancedGapMatrix to extract the service resource ID, start and end times, and grade of each slot.

1// FSL.GradeSlotsService class
2// The getGradedMatrix method returns a matrix of resource id's AND graded time slots
3
4Id serviceAppointmentId = '08p1N000000qN4sQAE';
5Id schedulingPolicyId=[SELECT Id FROM FSL__Scheduling_Policy__c WHERE Name='Customer First' LIMIT 1].Id;
6
7// GENERATE the graded time slots for the service appointment
8FSL.GradeSlotsService mySlotService = new FSL.GradeSlotsService(schedulingPolicyId,serviceAppointmentId);
9
10// STORE the matrix of service resource id's and graded time slots
11FSL.AdvancedGapMatrix myResultMatrix = mySlotService.getGradedMatrix(true);
12
13Map<Id,FSL.ResourceScheduleData> mySRGradedTimeSlotMap = myResultMatrix.ResourceIDToScheduleData;
14for (Id thisresourceid : mySRGradedTimeSlotMap.keySet()){
15    for (FSL.SchedulingOption thisso : mySRGradedTimeSlotMap.get(thisresourceid).SchedulingOptions ) {
16        system.debug('***** Resource Id' + thisresourceid);
17        system.debug('***** Start - ' + thisso.Interval.Start);
18        system.debug('***** Finish - ' + thisso.Interval.Finish);
19        system.debug('****** Grade - ' + thisso.Grade);
20    }
21}