Professional Services Automation Apex API Developer Reference

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 Schedule creation.

This class contains deprecated items.

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

Name Type Description
scheduleDetail pse.SchedulingStrategyService.ScheduleDetail An object of ScheduleDetail.

Return Value

This service returns ProposedScheduleDetail object.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

// This sample code is to Prepare Schedule and Schedule Exception using EndDate Level strategy
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;
    // Number of hours for schedule
    schDet.scheduledHours = 40;
    
    // Creating an object of SchedulingStrategyService
    pse.SchedulingStrategyService ser = new pse.SchedulingStrategyService();
    
    // Calling prepareSchedule API method
    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());
}

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

Name Type Description
scheduleDetails List<pse.SchedulingStrategyService.ScheduleDetail> A List of ScheduleDetail objects. The list should have same type of strategy requests.

Return Value

This service returns a List of ProposedScheduleDetail objects.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

// This sample code is to Prepare Schedule and Schedule Exception using EndDate Level strategy
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;
    // Number of hours for schedule
    schDet.scheduledHours = 40;
    
    // Creating an object of SchedulingStrategyService
    pse.SchedulingStrategyService ser = new pse.SchedulingStrategyService();
    
    // Calling prepareSchedule API method
    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

Name Type Description
rescheduleWrapperList List<pse.SchedulingStrategyService.RescheduleWrapper> A list of RescheduleWrapper.

Exceptions Thrown

Value Description
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

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

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];
    // Creating a list of RescheduleWrapper
    List<pse.SchedulingStrategyService.RescheduleWrapper> wrapperList = new List<pse.SchedulingStrategyService.RescheduleWrapper>();
    
    for(integer i = 0;i<MaxScheduleLimit;i++)
    {
        // Creating an object of SchedulePattern.
        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;
        
        // Creating an object of CustomScheduleDetail.
        pse.SchedulingStrategyService.CustomScheduleDetail schDet = new pse.SchedulingStrategyService.CustomScheduleDetail();
        // Start date of schedule.
        schDet.startDate = date.valueOf('2014-08-1');
        // End date of schedule.
        schDet.endDate = date.valueOf('2014-08-15');
        // Schedule pattern of schedule.
        schDet.schedulePattern = schPat;
        // Number of hours for schedule.
        schDet.scheduledHours = 40;
        
        // Creating an object of RescheduleWrapper
        pse.SchedulingStrategyService.RescheduleWrapper rescheduleWrapper = new pse.SchedulingStrategyService.RescheduleWrapper();
        // Resource id for schedule.
        schDet.resourceId = contactsList[i].id;
        
        rescheduleWrapper.ScheduleDetail = schDet;
        rescheduleWrapper.scheduleId = schedulesList[i].Id;
        wrapperList.add(rescheduleWrapper);
    }
    pse.SchedulingStrategyService ser = new pse.SchedulingStrategyService();
    try{
        //Calling reschedule API method
        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

Name Type Description
splitRescheduleWrapperList List<pse.SchedulingStrategyService.SplitRescheduleWrapper> The list of SplitRescheduleWrapper.

Exceptions Thrown

Value Description
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

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

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]
        
        // Creating a list of SplitRescheduleWrapper
        List<pse.SchedulingStrategyService.SplitRescheduleWrapper> wrapperList = new List<pse.SchedulingStrategyService.SplitRescheduleWrapper>();
        // Creating an object of EndDateLevelScheduleDetail
        pse.SchedulingStrategyService.EndDateLevelScheduleDetail schDet1 = new pse.SchedulingStrategyService.EndDateLevelScheduleDetail();
        // Start date of schedule.
        schDet1.startDate = System.Today();
        // End date of schedule.
        schDet1.endDate = System.Today() + 7;
        // Resource id for schedule.
        schDet1.resourceId = contactsList.get(0).Id;
        // Number of hours for schedule.
        schDet1.scheduledHours = 40;
        
        // Creating an object of SplitRescheduleWrapper
        pse.SchedulingStrategyService.SplitRescheduleWrapper wrapper1 = new pse.SchedulingStrategyService.SplitRescheduleWrapper();
        
        wrapper1.scheduleDetail = schDet1;
        wrapper1.assignment = assignmentList.get(0).id;
        wrapper1.markAssignmentAsClosedFlag = true;
        
        wrapperList.add(wrapper1);
        
        // Creating an object of EndDateLevelScheduleDetail
        pse.SchedulingStrategyService.EndDateLevelScheduleDetail schDet2 = new pse.SchedulingStrategyService.EndDateLevelScheduleDetail();
        // Start date of schedule.
        schDet2.startDate = System.Today();
        // End date of schedule.
        schDet2.endDate = System.Today() + 7;
        // Resource id for schedule.
        schDet2.resourceId = contactsList.get(1).Id;
        // Number of hours for schedule.
        schDet2.scheduledHours = 40;
        
        // Creating an object of SplitRescheduleWrapper
        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
        {
            // Calling splitReschedule API Method
            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

Name Type Description
request pse.SchedulingStrategyService.RescheduleWrapper An object of RescheduleWrapper.

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

Name Type Description
request pse.SchedulingStrategyService.SplitRescheduleWrapper An object of SplitRescheduleWrapper.

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

Name Type Description
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

ScheduleDetailField

global ScheduleDetailField()

pse.SchedulingStrategyService.SplitRescheduleWrapper

global inherited sharing class SplitRescheduleWrapper

The structure for Split Reschedule related input values that are common for all strategy types.

Properties

Name Type Description
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

Name Type Description
scheduleDetail pse.SchedulingStrategyService.ScheduleDetail The new Schedule's Scheduling strategy and details.
scheduleId Id Schedule Id which needs to be updated.

pse.SchedulingStrategyService.ScheduleDetail

global abstract inherited sharing class ScheduleDetail

The structure for Schedule related input values that are common for all strategy types.

Properties

Name Type Description
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.

This class extends pse.SchedulingStrategyService.ScheduleDetail

Properties

Name Type Description
scheduledHours Double The total number of scheduled hours.

Methods

resolveImplementation

global override Type resolveImplementation()

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.

This class extends pse.SchedulingStrategyService.ScheduleDetail

Properties

Name Type Description
scheduledHours Double The total number of scheduled hours.

Methods

resolveImplementation

global override Type resolveImplementation()

enumerateFields

global override virtual Map<String, pse.SchedulingStrategyService.ScheduleDetailField> enumerateFields()

pse.SchedulingStrategyService.AdjustHoursScheduleDetail

global inherited sharing class AdjustHoursScheduleDetail extends ScheduleDetail

The structure for Schedule related input values that will be used in "AdjustHours" Strategy types.

This class extends pse.SchedulingStrategyService.ScheduleDetail

Properties

Name Type Description
scheduledHours Double The total number of scheduled hours.
respectHoliday Boolean A Boolean value that respects holidays.

Methods

resolveImplementation

global override Type resolveImplementation()

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.

This class extends pse.SchedulingStrategyService.ScheduleDetail

Properties

Name Type Description
percentAllocationRows List<pse.SchedulingStrategyService.PercentAllocationRow> A list of PercentAllocationRow.
respectHoliday Boolean A Boolean value that respects holidays.

Methods

resolveImplementation

global override Type resolveImplementation()

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.

This class extends pse.SchedulingStrategyService.ScheduleDetail

Properties

Name Type Description
schedulePattern pse.SchedulingStrategyService.SchedulePattern A SchedulePattern for the custom schedule strategy.
scheduledHours Double The total number of scheduled hours.

Methods

resolveImplementation

global override Type resolveImplementation()

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.

This class extends pse.SchedulingStrategyService.ScheduleDetail

Methods

resolveImplementation

global override Type resolveImplementation()

pse.SchedulingStrategyService.SchedulePattern

global inherited sharing class SchedulePattern

The structure for input variables for Schedule creation using "Custom" strategy types.

Properties

Name Type Description
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.

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

Name Type Description
schedule pse.SchedulingStrategyService.SchedulePattern An object of SchedulePattern.
totalHours Double The total number of scheduled hours.
scheduleExceptions List<pse.SchedulingStrategyService.SchedulePattern> A list of SchedulePattern.

pse.SchedulingStrategyService.PercentAllocationRow

global inherited sharing class PercentAllocationRow

The structure for the information (startDate, endDate, percentAllocated) related to each Percent Allocation Row.

Properties

Name Type Description
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)

© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.