OAAS Class
Namespace
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)
Signature
public static Id optimize(FSL.OAASRequest request)
Parameters
- request
- Type: FSL.OAASRequest
- 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.
DateTime start=Datetime.now();
DateTime finish=Datetime.now().addDays(3);
LIST<Id> lstServiceTerritories = new List<Id>();
lstServiceTerritories.add('0Hh0b000000cIwsCAE');
FSL.OAASRequest oaasRequest = new FSL.OAASRequest();
oaasRequest.allTasksMode = true;
oaasRequest.filterFieldAPIName = null;
oaasRequest.start = start;
oaasRequest.finish = finish;
oaasRequest.includeServicesWithEmptyLocation = false;
oaasRequest.locations = lstServiceTerritories;
oaasRequest.schedulingPolicyID = 'a0N4E0000031HKkUAM';
FSL.OAAS oaas = new FSL.OAAS();
id optRequest = oaas.optimize(oaasRequest);
reshuffle(serviceId, policyId)
Signature
public static Id reshuffle(Id serviceId, Id policyId)
Parameters
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
FSL.OAAS oaas = new FSL.OAAS();
id optRequest = oaas.reshuffle('08p4E000000M21CQAS', 'a0N4E0000031HKkUAM');
resourceDayOptimization(resourceId, policyId, horizon, includeAllTasks, includeOnlyResourceFutureSA, radius, candidateSasFields, unschedulableServicesField, maxOptRuntime)
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
resourceDayOptimization(resourceId, policyId, horizon, includeAllTasks, includeOnlyResourceFutureSA, radius, candidateSasFields, unschedulableServicesField, maxOptRuntime, nowTimeOnSchedule)
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.
Usage
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'.
FSL.OAAS a = new FSL.OAAS();
//SET the horizon interval
DateTime start = DateTime.newInstanceGmt(DateTime.Now().dateGmt(), Time.newInstance(0,0,0,0));
DateTime finish = start.addDays(3);
FSL.TimeInterval horizon = new FSL.TimeInterval(start,finish);
//SELECT the candidatesServices
List<ServiceAppointment> services = [SELECT Id FROM ServiceAppointment WHERE Id IN
(Service Appointment ID,Service Appointment ID) ];
SET<Id> candidatesIds = new SET<Id>();
FOR(ServiceAppointment service : services) {
candidatesIds.add(service.Id);
}
//SET the RSO required appointment services
Set<Id> requiredSaIds = new Set<Id>();
List<ServiceAppointment> services2 = [SELECT Id FROM ServiceAppointment WHERE Id=Service Appointment ID];
FOR(ServiceAppointment service : services2) {
requiredSaIds.add(service.Id);
}
//START the RSO process
Id requestId = a.resourceDayOptimization(Service Resource ID,Scheduling Policy ID,
horizon,false,true,50,candidatesIds,requiredSaIds,60,DateTime.newInstance(2018,1,0,0,0,0));
resourceDayOptimization(resourceId, policyId, horizon, includeAllTasks, includeOnlyResourceFutureSA, radius, candidateSas, unschedulableServices, maxOptRuntime)
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
resourceDayOptimization(resourceId, policyId, horizon, includeAllTasks, includeOnlyResourceFutureSA, radius, candidateSas, unschedulableServices, maxOptRuntime, nowTimeOnSchedule)
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.
Usage
Example
FSL.OAAS a = new FSL.OAAS();
//SET the horizon interval
DateTime start = DateTime.newInstanceGmt(DateTime.Now().dateGmt(), Time.newInstance(0,0,0,0));
DateTime finish = start.addDays(3);
FSL.TimeInterval horizon = new FSL.TimeInterval(start,finish);
//SELECT the candidatesServices
List<ServiceAppointment> services = [SELECT Id FROM ServiceAppointment WHERE Id IN ('08p4E00000017Gp','08p4E00000017Go') ];
SET<Id> candidatesIds = new SET<Id>();
FOR(ServiceAppointment service : services) {
candidatesIds.add(service.Id);
}
//SET the RSO required appointment services
Set<Id> requiredSaIds = new Set<Id>();
List<ServiceAppointment> services2 = [SELECT Id FROM ServiceAppointment WHERE Id='08p4E00000017Gq'];
FOR(ServiceAppointment service : services2) {
requiredSaIds.add(service.Id);
}
//START the RSO process
Id requestId = a.resourceDayOptimization('0Hn4E0000004JRS','a1w4E000000Ac6S',horizon,false,true,50,
candidatesIds,requiredSaIds,60,DateTime.newInstance(2018,1,0,0,0,0));