OAAS Class

Contains all the methods used in the available optimization services, such as global or in-day optimizations, reshuffle operations, and resource schedule optimizations.

Namespace 

FSL

Usage 

If you call OAAS APIs, running asynchronously, from the following methods, you receive a Database.executeBatch exception error message.

  • start batch Apex method
  • execute batch Apex method
  • future methods

The limitation doesn’t apply if you’re using Enhanced Scheduling and Optimization. See Using Batch Apex & Future Methods in the Apex Developer Guide.

OAAS Methods 

OAAS includes the following methods.

optimize(request) 

Returns the optimization request ID of the global optimization process that was triggered. If the scheduling policy includes an in-day optimization Boolean that’s set to true, the request triggers an in-day optimization.

Signature 

public static Id optimize(FSL.OAASRequest request)

Parameters 

request

Type: FSL.OAASRequest

The optimization request.

Return Value 

Type: Id

Record ID of the optimization request.

Example 

This example creates an instance of the OAASRequest class that holds all the details of the optimization call being initiated. Next, the example calls the optimize method and passes in the request.

1DateTime start=Datetime.now();
2DateTime finish=Datetime.now().addDays(3);
3
4LIST<Id> lstServiceTerritories = new List<Id>();
5lstServiceTerritories.add('0Hh0b000000cIwsCAE');
6
7FSL.OAASRequest oaasRequest = new FSL.OAASRequest();
8oaasRequest.allTasksMode = true;
9oaasRequest.filterFieldAPIName = null;
10oaasRequest.start = start;
11oaasRequest.finish = finish;
12oaasRequest.includeServicesWithEmptyLocation = false;
13oaasRequest.locations = lstServiceTerritories;
14oaasRequest.schedulingPolicyID = 'a0N4E0000031HKkUAM';
15
16FSL.OAAS oaas = new FSL.OAAS();
17id optRequest = oaas.optimize(oaasRequest);

reshuffle(serviceId, policyId) 

Returns the optimization request ID of a reshuffle operation that has begun on a given service appointment.

Signature 

public static Id reshuffle(Id serviceId, Id policyId)

Parameters 

serviceId

Type: Id

The record ID of the service appointment that must be scheduled.

policyId

Type: Id

The record ID of the scheduling policy being used to schedule the service appointment.

Return Value 

Type: Id

Record ID of the optimization request.

Usage 

The Reshuffle action is used when a high-priority service appointment must be scheduled within a full schedule. It runs a “mini-optimization” that attempts to reshuffle the schedule to accommodate the appointment.

To learn more about the Reshuffle action, see Reschedule Service Appointments.

Example 

1FSL.OAAS oaas = new FSL.OAAS();
2id optRequest = oaas.reshuffle('08p4E000000M21CQAS', 'a0N4E0000031HKkUAM');

resourceDayOptimization(resourceId, policyId, horizon, includeAllTasks, includeOnlyResourceFutureSA, radius, candidateSasFields, unschedulableServicesField, maxOptRuntime) 

Returns the optimization request ID with the details of the optimization call. This method runs resource schedule optimization—the optimization of a single service resource’s schedule—using the parameters provided.

Signature 

public static Id resourceDayOptimization(Id resourceId, Id policyId, FSL.TimeInterval horizon, Boolean includeAllTasks, Boolean includeOnlyResourceFutureSA, Decimal radius, String candidateSasFields, String unschedulableServicesField, Decimal maxOptRuntime)

Parameters 

resourceId

Type: Id

The record ID of the service resource whose schedule is being optimized.

policyId

Type: Id

The record ID of the scheduling policy being used to schedule the service appointment.

horizon

Type: FSL.TimeInterval

The time frame used to run resource schedule optimization.

includeAllTasks

Type: Boolean

If true, all relevant service appointments within the time frame are considered during optimization. If false, only unscheduled service appointments are considered, and all scheduled service appointments are pinned (unmovable).

includeOnlyResourceFutureSA

Type: Boolean

If true, only service appointments that are already assigned to the service resource are considered during optimization. If false, service appointments assigned to other service resources are also considered.

radius

Type: Decimal

The suggested distance between required service appointments and adjacent appointments. Required appointments are defined by the unschedulableServicesField parameter. Resource schedule optimization tries to group service appointments so that their distance from a required appointment is less than this radius. Appointments that are further from a required appointment can still be scheduled, but are deprioritized. If null, the data is not filtered based on the radius.

candidateSasFields

Type: String

Boolean service appointment field that indicates which appointments are candidates to be scheduled.

unschedulableServicesField

Type: String

Boolean service appointment field that indicates whether a service appointment is required (pinned), meaning it must remain on the schedule during resource schedule optimization.

maxOptRuntime

Type: Decimal

Total time in seconds during which the optimization results must be returned. This parameter only enforces the optimization time, and does not include optimization queue or Apex job queue times. If null, the default value of 30 seconds is used.

Usage 

To learn more about resource schedule optimization, see Optimize a Single Resource’s Schedule.

Return Value 

Type: Id

Record ID of the optimization request.

resourceDayOptimization(resourceId, policyId, horizon, includeAllTasks, includeOnlyResourceFutureSA, radius, candidateSasFields, unschedulableServicesField, maxOptRuntime, nowTimeOnSchedule) 

Returns the optimization request ID with the details of the optimization call. This method runs resource schedule optimization—the optimization of a single service resource’s schedule—using the parameters provided.

Signature 

public static Id resourceDayOptimization(Id resourceId, Id policyId, FSL.TimeInterval horizon, Boolean includeAllTasks, Boolean includeOnlyResourceFutureSA, Decimal radius, String candidateSasFields, String unschedulableServicesField, Decimal maxOptRuntime, Datetime nowTimeOnSchedule)

Parameters 

resourceId

Type: Id

The record ID of the service resource whose schedule is being optimized.

policyId

Type: Id

The record ID of the scheduling policy being used to schedule the service appointment.

horizon

Type: FSL.TimeInterval

The time frame used to run resource schedule optimization.

includeAllTasks

Type: Boolean

If true, all relevant service appointments within the time frame are considered during optimization. If false, only unscheduled service appointments are considered, and all scheduled service appointments are pinned (unmovable).

includeOnlyResourceFutureSA

Type: Boolean

If true, only service appointments that are already assigned to the service resource are considered during optimization. If false, service appointments assigned to other service resources are also considered.

radius

Type: Decimal

The suggested distance between required service appointments and adjacent appointments. Required appointments are defined by the unschedulableServicesField and nowTimeOnSchedule parameters. Resource schedule optimization tries to group service appointments so that their distance from a required appointment is less than this radius. Appointments that are further from a required appointment can still be scheduled, but are deprioritized. If null, the data is not filtered based on the radius.

candidateSasFields

Type: String

Boolean service appointment field that indicates which appointments are candidates to be scheduled.

unschedulableServicesField

Type: String

Boolean service appointment field that indicates whether a service appointment is required (pinned), meaning it must it must remain on the schedule during resource schedule optimization.

maxOptRuntime

Type: Decimal

Total time in seconds during which the optimization results must be returned. This parameter only enforces the optimization time, and does not include optimization queue or Apex job queue times. If null, the default value of 30 seconds is used.

nowTimeOnSchedule

Type: Datetime

An appointment whose scheduled start time is earlier than this time is considered required and isn’t updated during resource schedule optimization. Because resource schedule optimization is asynchronous, this parameter indicates when optimization was initiated. For example, if nowTimeOnSchedule is set to April 17, 2018, 10:30, appointments with an earlier scheduled start time are considered required and excluded from resource schedule optimization.

Return Value 

Type: Id

Record ID of the optimization request.

Usage 

To learn more about resource schedule optimization, see Optimize a Single Resource’s Schedule.

Example 

To use this code sample, replace the ID placeholders—for example, Service Appointment ID—with record IDs from your org. Surround the IDs with single quotes: '08p4E00000017Gq'.

1FSL.OAAS a = new FSL.OAAS();
2
3//SET the horizon interval
4DateTime start = DateTime.newInstanceGmt(DateTime.Now().dateGmt(), Time.newInstance(0,0,0,0));
5DateTime finish = start.addDays(3);
6FSL.TimeInterval horizon = new FSL.TimeInterval(start,finish);
7
8//SELECT the candidatesServices
9List<ServiceAppointment> services = [SELECT Id FROM ServiceAppointment WHERE Id IN 
10    (SERVICE_APPOINTMENT_ID,SERVICE_APPOINTMENT_ID) ];
11SET<Id> candidatesIds = new SET<Id>();
12FOR(ServiceAppointment service : services) {
13    candidatesIds.add(service.Id);
14}
15
16//SET the RSO required appointment services
17Set<Id> requiredSaIds = new Set<Id>();
18List<ServiceAppointment> services2 = [SELECT Id FROM ServiceAppointment WHERE Id=SERVICE_APPOINTMENT_ID];
19FOR(ServiceAppointment service : services2) {
20    requiredSaIds.add(service.Id);
21}
22
23//START the RSO process
24Id requestId = a.resourceDayOptimization(SERVICE_RESOURCE_ID,SCHEDULING_POLICY_ID,
25    ​horizon,false,true,50,candidatesIds,requiredSaIds,60,DateTime.newInstance(2018,1,0,0,0,0));

Where SERVICE_APPOINTMENT_ID, SERVICE_RESOURCE_ID, and SCHEDULING_POLICY_ID are variables.

resourceDayOptimization(resourceId, policyId, horizon, includeAllTasks, includeOnlyResourceFutureSA, radius, candidateSas, unschedulableServices, maxOptRuntime) 

Returns the optimization request ID with the details of the optimization call. This method runs resource schedule optimization—the optimization of a single service resource’s schedule—using the parameters provided.

Signature 

public static Id resourceDayOptimization(Id resourceId, Id policyId, FSL.TimeInterval horizon, Boolean includeAllTasks, Boolean includeOnlyResourceFutureSA, Decimal radius, Set<String> candidateSas, Set<String> unschedulableServices, Decimal maxOptRuntime)

Parameters 

resourceId

Type: Id

The record ID of the service resource whose schedule is being optimized.

policyId

Type: Id

The record ID of the scheduling policy being used to schedule the service appointment.

horizon

Type: FSL.TimeInterval

The time frame used to run resource schedule optimization.

includeAllTasks

Type: Boolean

If true, all relevant service appointments within the time frame are considered during optimization. If false, only unscheduled service appointments are considered, and all scheduled service appointments are pinned (unmovable).

includeOnlyResourceFutureSA

Type: Boolean

If true, only service appointments that are already assigned to the service resource are considered during optimization. If false, service appointments assigned to other service resources are also considered.

radius

Type: Decimal

The suggested distance between required service appointments and adjacent appointments. Required appointments are defined by the unschedulableServices parameter. Resource schedule optimization tries to group service appointments so that their distance from a required appointment is less than this radius. Appointments that are further from a required appointment can still be scheduled, but are deprioritized. If null, the data is not filtered based on the radius.

candidateSas

Type: Set<Id>

Set of IDs of service appointments that are candidates for scheduling.

unschedulableServices

Type: Set<Id>

Set of IDs of service appointments that are required (pinned), meaning they must remain on the schedule during resource schedule optimization

maxOptRuntime

Type: Decimal

Total time in seconds during which the optimization results must be returned. This parameter only enforces the optimization time, and does not include optimization queue or Apex job queue times. If null, the default value of 30 seconds is used.

Usage 

To learn more about resource schedule optimization, see Optimize a Single Resource’s Schedule.

Return Value 

Type: Id

Record ID of the optimization request.

resourceDayOptimization(resourceId, policyId, horizon, includeAllTasks, includeOnlyResourceFutureSA, radius, candidateSas, unschedulableServices, maxOptRuntime, nowTimeOnSchedule) 

Returns the optimization request ID with the details of the optimization call. This method runs resource schedule optimization—the optimization of a single service resource’s schedule—using the parameters provided.

Signature 

public static Id resourceDayOptimization(Id resourceId, Id policyId, FSL.TimeInterval horizon, Boolean includeAllTasks, Boolean includeOnlyResourceFutureSA, Decimal radius, Set<String> candidateSas, Set<String> unschedulableServices, Decimal maxOptRuntime, Datetime nowTimeOnSchedule)

Parameters 

resourceId

Type: Id

The record ID of the service resource whose schedule is being optimized.

policyId

Type: Id

The record ID of the scheduling policy being used to schedule the service appointment.

horizon

Type: FSL.TimeInterval

The time frame used to run resource schedule optimization.

includeAllTasks

Type: Boolean

If true, all relevant service appointments within the time frame are considered during optimization. If false, only unscheduled service appointments are considered, and all scheduled service appointments are pinned (unmovable).

includeOnlyResourceFutureSA

Type: Boolean

If true, only service appointments that are already assigned to the service resource are considered during optimization. If false, service appointments assigned to other service resources are also considered.

radius

Type: Decimal

The suggested distance between required service appointments and adjacent appointments. Required appointments are defined by the unschedulableServices and nowTimeOnSchedule parameters. Resource schedule optimization tries to group service appointments so that their distance from a required appointment is less than this radius. Appointments that are further from a required appointment can still be scheduled, but are deprioritized. If null, the data is not filtered based on the radius.

candidateSas

Type: Set<Id>

Set of IDs of service appointments that are candidates for scheduling.

unschedulableServices

Type: Set<Id>

Set of IDs of service appointments that are required, meaning they must remain on the schedule during resource schedule optimization. These appointments may be moved to a different time slot, but they will continue to comply with their Earliest Start Permitted and Due Date values.

maxOptRuntime

Type: Decimal

Total time in seconds during which the optimization results must be returned. This parameter only enforces the optimization time, and does not include optimization queue or Apex job queue times. If null, the default value of 30 seconds is used.

nowTimeOnSchedule

Type: Datetime

Optional. An appointment whose scheduled start time is earlier than this time is considered required and isn’t updated during resource schedule optimization. Because resource schedule optimization is asynchronous, this parameter indicates when optimization was initiated. For example, if nowTimeOnSchedule is set to April 17, 2018, 10:30, appointments with an earlier scheduled start time are considered required and excluded from resource schedule optimization.

Return Value 

Type: Id

Record ID of the optimization request.

Usage 

To learn more about resource schedule optimization, see Optimize a Single Resource’s Schedule.

Example 

1FSL.OAAS a = new FSL.OAAS();
2
3//SET the horizon interval
4DateTime start = DateTime.newInstanceGmt(DateTime.Now().dateGmt(), Time.newInstance(0,0,0,0));
5DateTime finish = start.addDays(3);
6FSL.TimeInterval horizon = new FSL.TimeInterval(start,finish);
7
8//SELECT the candidatesServices
9List<ServiceAppointment> services = [SELECT Id FROM ServiceAppointment WHERE Id IN ('08p4E00000017Gp','08p4E00000017Go') ];
10SET<Id> candidatesIds = new SET<Id>();
11FOR(ServiceAppointment service : services) {
12    candidatesIds.add(service.Id);
13}
14
15//SET the RSO required appointment services
16Set<Id> requiredSaIds = new Set<Id>();
17List<ServiceAppointment> services2 = [SELECT Id FROM ServiceAppointment WHERE Id='08p4E00000017Gq'];
18FOR(ServiceAppointment service : services2) {
19    requiredSaIds.add(service.Id);
20}
21
22//START the RSO process
23Id requestId = a.resourceDayOptimization('0Hn4E0000004JRS','a1w4E000000Ac6S',horizon,false,true,50,
24    ​candidatesIds,requiredSaIds,60,DateTime.newInstance(2018,1,0,0,0,0));