Newer Version Available
RecurringAppointmentsManager Class
Namespace
Usage
RecurringAppointmentsManager is an Apex class that takes the RecurringPattern class as a required parameter, and returns a list of RecurringSequence appointments that recur weekly.
RecurringAppointmentsManager Methods
RecurringAppointmentsManager includes the following static method.
getRecurringAppointmentsSlots
Signature
Parameters
- ServiceID
- Type: Id
- Required. The ID of a service appointment that represents a recurring visit. This record defines the scheduling requirements and constraints for each appointment in the recurring visits sequence. All visits use the location, required resources, skill requirements, and other constraints that are associated with this service appointment.
- PolicyID
- Type: Id
- Required. The policy to be used to get the relevant work rules and objectives for the operation.
- CalendarOperatingHoursId
- Type: Id
- Required. The ID of the operating hours used to determine the structure of the slots returned by the API.
- RecurringPattern
- Type: RecurringPattern Class
- Required. This class instance is sent as a parameter that contains all the required details from the recurring pattern.
- SchedulingOptionsCount
- Type: Integer
- Required. Indicates how many sets of scheduling options the API returns. You can have between one and three sets of options for the recurring appointment. If you select three, but fewer than three sets of recurrence scheduling options are available, you receive however many options are found given your constraints.
Return Value
Type: List RecurringSequence
Usage
This method returns a list of recurring appointments to repeat weekly.
This method only returns a list of potential scheduling options in the RecurringSequence class and doesn’t schedule the recurring appointments. Similar to the getSlots method for AppointmentBookingService , you use the response from getRecurringAppointmentsSlots to create a list of records to insert, and then schedule the appointments.
The time constraint fields on ServiceAppointment that you pass into the API are used for all appointments within the recurrence and determine the availability of scheduling options. Ensure that there’s a significant difference between EarliestStartTime and DueDate fields. For example, if you must schedule six appointments, and your customer only has visiting hours on Monday, you need six weeks to schedule all visits. Therefore, make sure you set EarliestStartTime and DueDate to at least six weeks apart. Don’t set other time constraint fields on the appointment that are more restrictive, such as ArrivalWindowStartTime and ArrivalWindowEndTime, which can further limit scheduling options.
If you need service to occur within a given time frame, for example 8 AM to 10 AM on a Monday, set the DaysOfWeek to Monday. Then, set the time frame using the visiting hours record that has operating hours time slots during your required time frame.
See the ServiceAppointment object reference for more information on time constraint fields.
Example 1: Using an Execution Script
The following code sample creates an instance of the RecurringPattern class. Then, it sets the properties for that recurring pattern. In this case, the code creates a recurring pattern that excludes weekends, and considers that the customer isn’t available on Tuesdays, needs two visits per week, and requires six total visits. It requests that the API return three scheduling options.
1//Fill the pattern object
2FSL.RecurringPattern pattern = new FSL.RecurringPattern();
3pattern.DaysOfWeek = new Set<FSL.RecurringPattern.DaysOfWeek>{FSL.RecurringPattern.DaysOfWeek.Monday, FSL.RecurringPattern.DaysOfWeek.Wednesday, FSL.RecurringPattern.DaysOfWeek.Thursday, FSL.RecurringPattern.DaysOfWeek.Friday};
4pattern.FrequencyType = FSL.RecurringPattern.FrequencyType.WEEKLY;
5pattern.Frequency = 2;
6pattern.NumberOfVisits = 6;
7
8Integer schedulingOptionsCount = 3;
9Id policyID = 'a1Lx00000004CUXEA2';
10Id serviceId = '08px000000NzmOeAAJ';
11Id operatingHoursId = '0OHx0000000D3ETGA0';
12
13//Call the API
14FSL.RecurringAppointmentSlots result = FSL.RecurringAppointmentsManager.getRecurringAppointmentsSlots(serviceId , policyID, operatingHoursId, schedulingOptionsCount, pattern);
15
16//Handle the response of the API (example only)
17for (Integer i=1 ; i<= result.recurringSequences.size() ; i++){
18 System.debug('Sequence number: ' + i);
19 System.debug('participatingResources details: /n' + result);
20 System.debug('visitSchedulingOptions details: /n' + result);
21 System.debug('averageObjectivesGrades details: /n' + result);
22 System.debug('sequenceScore details: /n' + result);
23 System.debug('firstPatternOccurrence details: /n' + result);
24}Example 2: Using a Method
This code sample uses a method to create the same recurring pattern.
1//Using a method (example):
2public callRecurringVisitsAPI(Id serviceID, Id policyID, Id calendarOperatingHoursId, Integer SchedulingOptionsCount) {
3
4//Fill the pattern object
5RecurringPattern pattern = new FSL.RecurringPattern();
6pattern.DaysOfWeek = new Set<RecurringPattern.DaysOfWeek>{RecurringPattern.DaysOfWeek.Monday, RecurringPattern.DaysOfWeek.Wednesday, RecurringPattern.DaysOfWeek.Thursday, RecurringPattern.DaysOfWeek.Friday};
7
8pattern.FrequencyType = RecurringPattern.FrequencyType.WEEKLY;
9pattern.Frequency = 2;
10pattern.NumberOfVisits = 6;
11
12//Call the API
13FSL.RecurringAppointmentSlots result = RecurringAppointmentsManager.getRecurringAppointmentsSlots(serviceID, policyID, calendarOperatingHoursId, SchedulingOptionsCount, pattern);
14}
15
16}