pse.SchedulingStrategyService
global without sharing class SchedulingStrategyService
This class contains a Scheduling API implementation for each type of Scheduling Strategy. There are inner classes for each type of Scheduling Strategy which have a method for the creation of schedules associated with assignments or resource requests.
This class contains deprecated items.
Enums
RepeatModes
Defines the period for which the schedule pattern will be repeated. Like WEEKS or MONTHS.
WEEKS |
The schedule pattern will be repeated using week as the period. |
Methods
prepareSchedule
global pse.SchedulingStrategyService.ProposedScheduleDetail prepareSchedule(pse.SchedulingStrategyService.ScheduleDetail scheduleDetail)
This method calculates a Schedule and ScheduleExceptions for the provided ScheduleDetail parameters.
Input Parameters
Return Value
This service returns ProposedScheduleDetail object.
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | static void testPrepareSchedule()
{
/**
* EndDateLevelScheduleDetail extends ScheduleDetail so here we can create an instance of EndDateLevelScheduleDetail as an over requirement.
* Here we can generate a schedule using any type of scheduling strategy by creating an instance of that class.
*/
pse.SchedulingStrategyService.EndDateLevelScheduleDetail schDet = new pse.SchedulingStrategyService.EndDateLevelScheduleDetail();
schDet.startDate = date.valueOf( '2013-12-08' );
schDet.endDate = date.valueOf( '2013-12-14' );
schDet.resourceId = resource.id;
schDet.scheduledHours = 40 ;
pse.SchedulingStrategyService ser = new pse.SchedulingStrategyService();
pse.SchedulingStrategyService.ProposedScheduleDetail ps = ser.prepareSchedule(schDet);
SchedulingStrategyService.SchedulePattern schPattern = ps.schedule;
system.assertEquals(date.valueOf( '2013-12-08' ), schPattern.startDate);
system.assertEquals(date.valueOf( '2013-12-13' ), schPattern.endDate);
system.assertEquals( 0 , ps.scheduleExceptions.size());
}
|
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | Contact res = [SELECT Id FROM Contact LIMIT 1 ];
pse.SchedulingStrategyService.SchedulePattern schedulePattern = new pse.SchedulingStrategyService.SchedulePattern();
schedulePattern.mondayHours = 4.00 ;
schedulePattern.tuesdayHours = 4.00 ;
schedulePattern.wednesdayHours = 8.00 ;
schedulePattern.thursdayHours = 3.00 ;
schedulePattern.fridayHours = 8.00 ;
schedulePattern.frequency = 3 ;
schedulePattern.mode = pse.SchedulingStrategyService.RepeatModes.WEEKS;
pse.SchedulingStrategyService.CustomScheduleDetail scheduleDetail = new pse.SchedulingStrategyService.CustomScheduleDetail();
scheduleDetail.startDate = date.valueOf( '2024-10-01' );
scheduleDetail.endDate = date.valueOf( '2024-10-31' );
scheduleDetail.schedulePattern = schedulePattern;
scheduleDetail.resourceId = res.Id;
scheduleDetail.scheduledHours = 120 ;
pse.SchedulingStrategyService service = new pse.SchedulingStrategyService();
pse.SchedulingStrategyService.ProposedScheduleDetail proposedSchedule = service.prepareSchedule(scheduleDetail);
SchedulingStrategyService.SchedulePattern proposedPattern = proposedSchedule.schedule;
Assert.areEqual(date.valueOf( '2024-10-01' ), proposedPattern.startDate);
Assert.areEqual(date.valueOf( '2025-01-13' ), proposedPattern.endDate);
|
prepareSchedules
global List<pse.SchedulingStrategyService.ProposedScheduleDetail> prepareSchedules(List<pse.SchedulingStrategyService.ScheduleDetail> scheduleDetails)
This method calculates Schedules and ScheduleExceptions for the provided ScheduleDetails parameter.
Input Parameters
Return Value
This service returns a List of ProposedScheduleDetail objects.
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | static void testPrepareSchedule()
{
/**
* EndDateLevelScheduleDetail extends ScheduleDetail so here we can create an instance of EndDateLevelScheduleDetail as an over requirement.
* Here we can generate a schedule using any type of scheduling strategy by creating an instance of that class.
*/
pse.SchedulingStrategyService.EndDateLevelScheduleDetail schDet = new pse.SchedulingStrategyService.EndDateLevelScheduleDetail();
schDet.startDate = date.valueOf( '2013-12-08' );
schDet.endDate = date.valueOf( '2013-12-14' );
schDet.resourceId = resource.id;
schDet.scheduledHours = 40 ;
pse.SchedulingStrategyService ser = new pse.SchedulingStrategyService();
pse.SchedulingStrategyService.ProposedScheduleDetail ps = ser.prepareSchedule(schDet);
SchedulingStrategyService.SchedulePattern schPattern = ps.schedule;
system.assertEquals(date.valueOf( '2013-12-08' ), schPattern.startDate);
system.assertEquals(date.valueOf( '2013-12-13' ), schPattern.endDate);
system.assertEquals( 0 , ps.scheduleExceptions.size());
}
|
reschedule
global Boolean reschedule(List<pse.SchedulingStrategyService.RescheduleWrapper> rescheduleWrapperList)
A global method to reschedule the provided list of schedules with a new proposed corresponding scheduling strategy in rescheduleWrapper. Operations performed as follows. • Deletes old Schedule Exceptions. • Updates the Schedule. • Inserts new Schedule Exceptions. • rescheduleWrapperList holds a new scheduling strategy and relevant parameters according to the scheduling strategy and Schedule id. Note: To use the reschedule method, users need Update permission on the pse__Schedule__c object.
Input Parameters
Exceptions Thrown
ProposedScheduleDetailException |
Occurs when the Schedule Id is null or any schedule is rescheduled more than once. |
Return Value
This service returns True if the Schedule updated then completed successfully.
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | static void testReschedule()
{
integer MaxScheduleLimit = 15 ;
List<Contact> contactsList = [select id FROM Contact limit MaxScheduleLimit];
List<Schedule__c> schedulesList = [select id from pse__Schedule__c limit MaxScheduleLimit];
List<pse.SchedulingStrategyService.RescheduleWrapper> wrapperList = new List<pse.SchedulingStrategyService.RescheduleWrapper>();
for (integer i = 0 ;i<MaxScheduleLimit;i++)
{
pse.SchedulingStrategyService.SchedulePattern schPat = new pse.SchedulingStrategyService.SchedulePattern();
schPat.mondayHours = 4.00 ;
schPat.tuesdayHours = 4.00 ;
schPat.wednesdayHours = 8.00 ;
schPat.thursdayHours = 3.00 ;
schPat.fridayHours = 8.00 ;
pse.SchedulingStrategyService.CustomScheduleDetail schDet = new pse.SchedulingStrategyService.CustomScheduleDetail();
schDet.startDate = date.valueOf( '2014-08-1' );
schDet.endDate = date.valueOf( '2014-08-15' );
schDet.schedulePattern = schPat;
schDet.scheduledHours = 40 ;
pse.SchedulingStrategyService.RescheduleWrapper rescheduleWrapper = new pse.SchedulingStrategyService.RescheduleWrapper();
schDet.resourceId = contactsList[i].id;
rescheduleWrapper.ScheduleDetail = schDet;
rescheduleWrapper.scheduleId = schedulesList[i].Id;
wrapperList.add(rescheduleWrapper);
}
pse.SchedulingStrategyService ser = new pse.SchedulingStrategyService();
try {
Boolean scheduledUpdated = ser.reschedule(wrapperList);
system. assert (scheduledUpdated, 'Schedules updation failed' );
}
catch (Exception ex)
{
system. assert ( false , 'Schedules updation failed : ' + ex.getMessage());
}
}
|
splitReschedule
global List<pse__Assignment__c> splitReschedule(List<pse.SchedulingStrategyService.SplitRescheduleWrapper> splitRescheduleWrapperList)
A global method to split and reschedule the schedules. • A new Schedule will be scheduled as per Scheduling strategy proposed in the SplitRescheduleWrapper's scheduleDetail object. • The old Schedule will be rescheduled by modifying its End date to one day less than the start date of the new Schedule defined under scheduleDetail. Operations performed as follows. • Updates the Schedule Exception for the old schedule. • Updates the old Schedule's end date to one day less than the start date of the new schedule. • If markAssignmentAsClosedFlag in Reschedule Wrapper is set to true then close the current assignment. • Inserts the new Schedule. • Inserts the new Schedule Exceptions. • Inserts the new Assignment. Note: To use the splitReschedule method, you need Create and Update permissions on the pse__Schedule__c object and Create permission on the pse__Assignment__c object. Additionally, When markAssignmentAsClosedFlag is true, splitReschedule updates assignments and Update Permission is required on the pse__Assignment__c object. In this case permission is checked that users can update the following pse_Assignment__c object fields: - pse__Status__c
- pse__Closed_for_Time_Entry__c
- pse__Closed_for_Expense_Entry__c
Input Parameters
Exceptions Thrown
ProposedScheduleDetailException |
Occurs when the Schedule Id is null or any schedule is rescheduled more than once. |
Return Value
This service returns a list of newly created assignments.
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | static void testSplitReschedule()
{
List<Contact> contactsList = [select id FROM Contact limit MaxScheduleLimit];
List<pse__Schedule__c> schedulesList = [select id from pse__Schedule__c limit MaxScheduleLimit];
List<pse__Assignment__c> assignmentList = [select id from pse__Assignment__c]
List<pse.SchedulingStrategyService.SplitRescheduleWrapper> wrapperList = new List<pse.SchedulingStrategyService.SplitRescheduleWrapper>();
pse.SchedulingStrategyService.EndDateLevelScheduleDetail schDet1 = new pse.SchedulingStrategyService.EndDateLevelScheduleDetail();
schDet1.startDate = System.Today();
schDet1.endDate = System.Today() + 7 ;
schDet1.resourceId = contactsList.get( 0 ).Id;
schDet1.scheduledHours = 40 ;
pse.SchedulingStrategyService.SplitRescheduleWrapper wrapper1 = new pse.SchedulingStrategyService.SplitRescheduleWrapper();
wrapper1.scheduleDetail = schDet1;
wrapper1.assignment = assignmentList.get( 0 ).id;
wrapper1.markAssignmentAsClosedFlag = true ;
wrapperList.add(wrapper1);
pse.SchedulingStrategyService.EndDateLevelScheduleDetail schDet2 = new pse.SchedulingStrategyService.EndDateLevelScheduleDetail();
schDet2.startDate = System.Today();
schDet2.endDate = System.Today() + 7 ;
schDet2.resourceId = contactsList.get( 1 ).Id;
schDet2.scheduledHours = 40 ;
pse.SchedulingStrategyService.SplitRescheduleWrapper wrapper2 = new pse.SchedulingStrategyService.SplitRescheduleWrapper();
wrapper2.scheduleDetail = schDet2;
wrapper2.assignment = assignmentList.get( 1 ).id;
wrapper2.markAssignmentAsClosedFlag = false ;
wrapperList.add(wrapper2);
pse.SchedulingStrategyService ser = new pse.SchedulingStrategyService();
List<Assignment__c> updatedAssignments;
try
{
updatedAssignments = ser.splitReschedule(wrapperList);
}
catch (Exception ex)
{
system. assert ( false , 'Schedules updation failed : ' + ex.getMessage());
}
pse__Assignment__c updatedOldAssignment1 = [select pse__Status__c, pse__Closed_For_Time_Entry__c, pse__End_date__c from pse__Assignment__c where id=: assignmentList.get( 0 ).id ];
system. assert (updatedOldAssignment1.pse__Status__c.equalsIgnoreCase( 'closed' ));
}
}
|
Deprecated
The following items are deprecated and not supported for use. We recommend that you stop using these items to avoid exceptions.
Methods
reschedule
Deprecated: Use reschedule(List rescheduleWrapperList) instead.
global Boolean reschedule(pse.SchedulingStrategyService.RescheduleWrapper request)
This global method reschedules a Schedule with a new proposed scheduling strategy in rescheduleWrapper.
Input Parameters
Return Value
This service returns True if the Schedule updated then completed successfully, False otherwise.
splitReschedule
Deprecated: Use splitReschedule(List splitRescheduleWrapperList) instead.
global pse__Assignment__c splitReschedule(pse.SchedulingStrategyService.SplitRescheduleWrapper request)
A global method to split and reschedule the Schedule.
Input Parameters
Return Value
This service returns an assignment object.
pse.SchedulingStrategyService.ScheduleDetailField
global inherited sharing class ScheduleDetailField
The structure for Metadata information related to the ScheduleDetail field.
Properties
dataType |
Type |
Data type of field.
|
name |
String |
API Name of field.
|
label |
String |
Label of field.
|
isRequired |
boolean |
Determine whether this field is required.
|
Methods
pse.SchedulingStrategyService.SplitRescheduleWrapper
global inherited sharing class SplitRescheduleWrapper
The structure for Split Reschedule related input values that are common for all strategy types.
Properties
scheduleDetail |
pse.SchedulingStrategyService.ScheduleDetail |
The new Schedule's Scheduling strategy and details.
|
assignment |
pse__Assignment__c |
Assignment which needs to be updated.
|
markAssignmentAsClosedFlag |
Boolean |
Update the assignment to a closed status. This is an optional parameter and is false by default.
|
pse.SchedulingStrategyService.RescheduleWrapper
global inherited sharing class RescheduleWrapper
The structure for Reschedule related input values that are common for all strategy types.
Properties
pse.SchedulingStrategyService.ScheduleDetail
global abstract inherited sharing class ScheduleDetail
The structure for Schedule related input values that are common for all strategy types.
Properties
startDate |
Date |
The Schedule's start date.
|
endDate |
Date |
The Schedule's end date.
|
resourceId |
Id |
The Id of the Resource for the Schedule.
|
Methods
resolveImplementation
global abstract Type resolveImplementation()
An abstract method to resolve the Schedule class dynamically at runtime.
getField
global virtual Object getField()
getField
global virtual Object getField(String key)
setField
global virtual void setField(String key, Object value)
enumerateFields
global virtual Map<String, pse.SchedulingStrategyService.ScheduleDetailField> enumerateFields()
pse.SchedulingStrategyService.EndDateLevelScheduleDetail
global inherited sharing class EndDateLevelScheduleDetail extends ScheduleDetail
The structure for Schedule related input values that will be used in the "EndDateLevelSchedule" schedule Strategy.
Properties
scheduledHours |
Double |
The total number of scheduled hours.
|
Methods
enumerateFields
global override virtual Map<String, pse.SchedulingStrategyService.ScheduleDetailField> enumerateFields()
pse.SchedulingStrategyService.IgnoreAvailabilityScheduleDetail
global inherited sharing class IgnoreAvailabilityScheduleDetail extends ScheduleDetail
The structure for Schedule related input values that will be used in "EndDateIgnoreAvailability" Schedule Strategy types.
Properties
scheduledHours |
Double |
The total number of scheduled hours.
|
Methods
enumerateFields
global override virtual Map<String, pse.SchedulingStrategyService.ScheduleDetailField> enumerateFields()
global inherited sharing class AdjustHoursScheduleDetail extends ScheduleDetail
The structure for Schedule related input values that will be used in "AdjustHours" Strategy types.
Properties
scheduledHours |
Double |
The total number of scheduled hours.
|
respectHoliday |
Boolean |
A Boolean value that respects holidays.
|
Methods
enumerateFields
global override virtual Map<String, pse.SchedulingStrategyService.ScheduleDetailField> enumerateFields()
pse.SchedulingStrategyService.PercentAllocationScheduleDetail
global inherited sharing class PercentAllocationScheduleDetail extends ScheduleDetail
The structure for Schedule related input values that will be used in "PercentAllocation" Strategy types.
Properties
Methods
enumerateFields
global override virtual Map<String, pse.SchedulingStrategyService.ScheduleDetailField> enumerateFields()
pse.SchedulingStrategyService.CustomScheduleDetail
global inherited sharing class CustomScheduleDetail extends ScheduleDetail
The structure for Schedule related input values that will be used in "Custom" Strategy types.
Properties
Methods
enumerateFields
global override virtual Map<String, pse.SchedulingStrategyService.ScheduleDetailField> enumerateFields()
pse.SchedulingStrategyService.ZeroHourScheduleDetail
global inherited sharing class ZeroHourScheduleDetail extends ScheduleDetail
The structure for Schedule related input values that will be used in "ZeroHour" Strategy types.
Methods
pse.SchedulingStrategyService.SchedulePattern
global inherited sharing class SchedulePattern
The structure for input variables for Schedule creation using "Custom" strategy types.
Properties
sundayHours |
Double |
Sunday hours of Schedule.
|
mondayHours |
Double |
Monday hours of Schedule.
|
tuesdayHours |
Double |
Tuesday hours of Schedule.
|
wednesdayHours |
Double |
Wednesday hours of Schedule.
|
thursdayHours |
Double |
Thursday hours of Schedule.
|
fridayHours |
Double |
Friday hours of Schedule.
|
saturdayHours |
Double |
Saturday hours of Schedule.
|
startDate |
Date |
Start date of Schedule.
|
endDate |
Date |
End date of Schedule.
|
frequency |
Integer |
Integer frequency defines the number of times follow the same schedule pattern for the defined mode. Default value is 1 which means every week(mode) defined pattern will repeat till the requested hours gets consumed. so as if 2 is the value, then in every 2 weeks(mode) the pattern will be repeated. 0 and positive values are valid, Any negative value entered, would be considered as default value(1). For frequency as 0, is a special case, schedule will be created for one week only irrespective of total hours or end date.
|
mode |
pse.SchedulingStrategyService.RepeatModes |
RepeatModes mode defines the period for which schedule pattern will be repeated as per the frequency. Default value is RepeatModes.WEEKS.
|
pse.SchedulingStrategyService.ProposedScheduleDetail
global inherited sharing class ProposedScheduleDetail
The structure for information returned in the output. It will contain the Schedule and ScheduleExceptions (related to Schedule_Exception__c PSA object) for that Schedule.
Properties
pse.SchedulingStrategyService.PercentAllocationRow
global inherited sharing class PercentAllocationRow
The structure for the information (startDate, endDate, percentAllocated) related to each Percent Allocation Row.
Properties
startDate |
Date |
Start date for Percent Allocation scheduling strategy.
|
endDate |
Date |
End date for Percent Allocation scheduling strategy.
|
percentAllocated |
Double |
PercentAllocation for Percent Allocation scheduling strategy.
|
pse.SchedulingStrategyService.ISchedulingStrategy
global interface ISchedulingStrategy
Common interface for the different schedule calculations.
Methods
prepareSchedule
ProposedScheduleDetail prepareSchedule(pse.SchedulingStrategyService.ScheduleDetail scheduleDetail)
pse.SchedulingStrategyService.IBulkifySchedulingStrategy
global interface IBulkifySchedulingStrategy
Common interface for the different schedule calculations in bulk. This is newly created interface to avoid packaging failure as we cannont add new method in global interface.
Methods
prepareSchedules
List<ProposedScheduleDetail> prepareSchedules(List<pse.SchedulingStrategyService.ScheduleDetail> scheduleDetails)
|