PSA Apex API Developer Reference


global with sharing class ScheduleService

a service that provides functionality relating to schedules. to understand schedules, call this service rather than query Schedule and ScheduleException separately and interpret the results. To make simple updates to existing schedules, call this service rather than use DML on Schedule and ScheduleException separately.



global static Map<Id, pse.ScheduleService.HoursDetail> getScheduledHoursForDates(Set<Id> scheduleIds, Date startDate, Date endDate)

This method does all the logic of looking at the specified schedules and their schedule exceptions and working out how many hours the resources are scheduled to work on specific dates.

Input Parameters

Name Type Description
scheduleIds Set<Id> The schedules to be queried.
startDate Date The start of the period you are requesting data for.
endDate Date The end of the period you are requesting data for.

Return Value

A map keyed on Schedule Id. The values detail the scheduled hours after schedule exceptions have been considered.

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.

//Use the service to find scheduled hours in October for a specific schedule.
Set<Id> scheduleIds = new Set<Id>{'a3W55000000pO2WEAU'};
Map<Id, pse.ScheduleService.HoursDetail> scheduleMap = pse.ScheduleService.getScheduledHoursForDates(
    Date.newInstance(2020, 10, 1),
    Date.newInstance(2020, 10, 31)

pse.ScheduleService.HoursDetail firstSchedule = scheduleMap.get('a3W55000000pO2WEAU');
String messageTemplate = 'Schedule runs from {0} to {1}\n';
String message = String.format(
    new List<String>{

for (Integer day = 1; day<=31; day++) {
    Date queryDate = Date.newInstance(2020, 10, day);

    //Map does not contain keys for dates outside the scheduled period
    if (firstSchedule.dateToHours.containsKey(queryDate)) {
        Decimal hoursScheduled = firstSchedule.dateToHours.get(queryDate);
        message += queryDate + ' -> ' + hoursScheduled + '\n';


global static List<pse.ScheduleService.UpdateScheduleResponse> updateSchedules(List<pse.ScheduleService.UpdateScheduleRequest> requests)

Amends the specified schedules and their schedule exceptions to change specific dates to the hours indicated in the request. If you want to make extensive changes to the schedule, such as changing the pattern for the whole scheduled period or altering the end date, we recommend that you use the pse.SchedulingStrategyService API. The return value contains one response for each request and indicates if the request was valid. For example, a request is invalid if you attempt to change a date outside the range of the schedule. Any DML errors are thrown as exceptions.

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.

//The Project Manager of Universal Internet has decided to put everybody's hours to zero on his birthday.
//Now they have no reason to miss his party.
Date specialDay = Date.newInstance(2020, 9,19);
List<pse__Assignment__c> asmts = [
    SELECT Id, pse__Schedule__c
    FROM pse__Assignment__c
    WHERE pse__Project__r.Name = 'Universal Internet'

List<pse.ScheduleService.UpdateScheduleRequest> requests = new List<pse.ScheduleService.UpdateScheduleRequest>();
for (Assignment__c asmt : asmts) {
    pse.ScheduleService.UpdateScheduleRequest request = new pse.ScheduleService.UpdateScheduleRequest();
    request.ScheduleId = asmt.pse__Schedule__c;
    request.Hours = new Map<Date, Decimal>();
    request.Hours.put(specialDay, 0);

List<ScheduleService.UpdateScheduleResponse> responses = pse.ScheduleService.updateSchedules(
for (ScheduleService.UpdateScheduleResponse response : responses) {
    if (response.Success) {
        //We could tell the person the good news
    } else {
        //His birthday is probably outside their schedule, we never checked.
        //But let's have a look at the messages anyway.
        System.debug(LoggingLevel.ERROR, response.Errors);


global inherited sharing class HoursDetail


Name Type Description
dateToHours Map<Date, Decimal> indicates how many hours are scheduled for each date in the range. The dates included in the map are the intersection of the scheduled period and the dates passed in the call to getScheduledHoursForDates.
scheduleStart Date the start date of the schedule.
scheduleEnd Date the end date of the schedule.


global inherited sharing class UpdateScheduleRequest

use instances of this object with updateschedules to edit schedules.


Name Type Description
ScheduleId Id the id of the schedule to be amended.
Hours Map<Date, Decimal> the keys are the dates to be amended, and the values are the new scheduled hours for each date. Only scheduled hours for dates included in this map are amended, scheduled hours for other dates are unchanged.


global inherited sharing class UpdateScheduleResponse

response object returned from updateschedules. Use the ScheduleId to match it to a request.


Name Type Description
ScheduleId Id the id of the updated schedule.
Success Boolean false if the request was invalid. true otherwise. invalid requests will not be processed.
Errors List<String> Any validation errors with the request will be stored here.
© Copyright 2009–2021, inc. All rights reserved. Various trademarks held by their respective owners.