Contains all the methods used in the available optimization services, such as global or in-day optimizations, reshuffle operations, and resource schedule optimizations.
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)
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.
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.
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)
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).
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.
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.
Boolean service appointment field that indicates whether a service appointment is required (pinned), meaning it must remain on the schedule during resource schedule optimization.
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.
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)
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).
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.
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.
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.
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.
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.
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();23//SET the horizon interval4DateTime 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);78//SELECT the candidatesServices9List<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}1516//SET the RSO required appointment services17Set<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}2223//START the RSO process24Id 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.
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)
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).
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.
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.
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.
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)
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).
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.
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.
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.
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.
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.
1FSL.OAAS a = new FSL.OAAS();23//SET the horizon interval4DateTime 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);78//SELECT the candidatesServices9List<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}1415//SET the RSO required appointment services16Set<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}2122//START the RSO process23Id requestId = a.resourceDayOptimization('0Hn4E0000004JRS','a1w4E000000Ac6S',horizon,false,true,50,24 candidatesIds,requiredSaIds,60,DateTime.newInstance(2018,1,0,0,0,0));