Professional Services Automation Apex API Developer Reference

pse.ScheduleResourceService

global with sharing class ScheduleResourceService

Contains methods and structures to retrieve weekly scheduled hours information for schedules.

Methods

getScheduledHoursForWeeks

global static pse.ScheduleResourceService.ScheduleResourceServiceResponse getScheduledHoursForWeeks(pse.ScheduleResourceService.ScheduleResourceServiceRequest scheduleResourceServiceRequest)

Enables you to retrieve weekly scheduled hours information for schedules.

Input Parameters

Name Type Description
scheduleResourceServiceRequest pse.ScheduleResourceService.ScheduleResourceServiceRequest ScheduleResourceService.ScheduleResourceServiceRequest request.

Return Value

Returns ScheduleResourceService.ScheduleResourceServiceResponse.

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.

/*
    ***************************************************************************************************************************
    Example 1: Displays an error details response when an invalid End Date (i.e End Date earlier than Start Date) is sent to 
    the scheduleHoursForWeeks method.
    ***************************************************************************************************************************
/*

Date currentDate = Date.today();
Id scheduleID = 'a1vHo0000022jT4IAI';

pse.ScheduleResourceService.ScheduleResourceServiceRequest request = new pse.ScheduleResourceService.ScheduleResourceServiceRequest();
request.ScheduleIds = new Set<Id>{ scheduleID };
request.WeekStartDay = pse.CalendarUtil.DayOfWeek.TUESDAY;
request.StartDate = currentDate;
request.EndDate = currentDate.addDays(-10);

pse.ScheduleResourceService.ScheduleResourceServiceResponse response = pse.ScheduleResourceService.getScheduledHoursForWeeks(request); 

List<pse.ScheduleResourceService.ScheduleWeeklyData> scheduleWeeklyData = response.WeeklySchedules;
Set<Id> remainingScheduleIds = response.RemainingScheduleIds;
List<pse.ScheduleResourceService.ErrorDetail> errorDetails = response.ErrorDetails;

System.debug('RemainingScheduleIds: ' + remainingScheduleIds);
System.debug('Schedule Weekly Data: ' + scheduleWeeklyData);
System.debug('Error Details: ' + errorDetails);

/*
    ***************************************************************************************************************************
    Example 2: Displays error details response when an invalid scheduleID is sent to the scheduleHoursForWeeks method.
    ***************************************************************************************************************************
/*

Date startDateOfValidScheduleID = Date.newInstance(2022, 08, 08);\
// Id of schedule which has schedule hours available for startDateOfValidScheduleID
Id validScheduleID = 'a1vHo0000022jT4IAI';
Id invalidScheduleID = 'a23530000018xkoAXB';

pse.ScheduleResourceService.ScheduleResourceServiceRequest request = new pse.ScheduleResourceService.ScheduleResourceServiceRequest();
request.ScheduleIds = new Set<Id>{ validScheduleID, invalidScheduleID };
request.WeekStartDay = pse.CalendarUtil.DayOfWeek.TUESDAY;
request.StartDate = startDateOfValidScheduleID.addDays(5);
request.EndDate = startDateOfValidScheduleID.addDays(10);

pse.ScheduleResourceService.ScheduleResourceServiceResponse response = pse.ScheduleResourceService.getScheduledHoursForWeeks(request); 

List<pse.ScheduleResourceService.ScheduleWeeklyData> scheduleWeeklyData = response.WeeklySchedules;
Set<Id> remainingScheduleIds = response.RemainingScheduleIds;
List<pse.ScheduleResourceService.ErrorDetail> errorDetails = response.ErrorDetails;

System.debug('RemainingScheduleIds: ' + remainingScheduleIds);
System.debug('Schedule Weekly Data: ' + scheduleWeeklyData);
System.debug('Error Details: ' + errorDetails);

/*
    ***************************************************************************************************************************
    Example 3: Displays error details when an invalid date range is sent to the scheduleHoursForWeeks method.
    ***************************************************************************************************************************
/*

Date startDateOfValidScheduleID = Date.newInstance(2022, 08, 08);
// Id of schedule which has schedule hours available for startDateOfValidScheduleID
Id validScheduleID = 'a1vHo0000022jT4IAI';

pse.ScheduleResourceService.ScheduleResourceServiceRequest request = new pse.ScheduleResourceService.ScheduleResourceServiceRequest();
request.ScheduleIds = new Set<Id>{ validScheduleID };
request.WeekStartDay = pse.CalendarUtil.DayOfWeek.TUESDAY;
request.StartDate = startDateOfValidScheduleID.addDays(-50);
request.EndDate = startDateOfValidScheduleID.addDays(-10);
request.BatchSize = 5 ; 
request.TransactionTimeLimit = 5000;

pse.ScheduleResourceService.ScheduleResourceServiceResponse response = pse.ScheduleResourceService.getScheduledHoursForWeeks(request); 

List<pse.ScheduleResourceService.ScheduleWeeklyData> scheduleWeeklyData = response.WeeklySchedules;
Set<Id> remainingScheduleIds = response.RemainingScheduleIds;
List<pse.ScheduleResourceService.ErrorDetail> errorDetails = response.ErrorDetails;

System.debug('RemainingScheduleIds: ' + remainingScheduleIds);
System.debug('Schedule Weekly Data: ' + scheduleWeeklyData);
System.debug('Error Details: ' + errorDetails);

/*
    ***************************************************************************************************************************
    Example 4: Sends a valid response when a valid request is sent to the scheduleHoursForWeeks method.
    ***************************************************************************************************************************
/*

Date startDate = Date.newInstance(2023, 06, 06);
// Ids of schedules which has schedule hours available for startDate
Set<Id> validScheduleIDs = new Set<Id>{ 'a1vHo0000022jT4IAI', 'a1vHo0000022jT5IAI', 'a1vHo0000022jT8IAI' };

pse.ScheduleResourceService.ScheduleResourceServiceRequest request = new pse.ScheduleResourceService.ScheduleResourceServiceRequest();
request.ScheduleIds = validScheduleIDs;
request.WeekStartDay = pse.CalendarUtil.DayOfWeek.TUESDAY;
request.StartDate = startDate;
request.EndDate = startDate.addDays(10);
request.BatchSize = 2 ; 
request.TransactionTimeLimit = 5000;

pse.ScheduleResourceService.ScheduleResourceServiceResponse response = pse.ScheduleResourceService.getScheduledHoursForWeeks(request); 

List<pse.ScheduleResourceService.ScheduleWeeklyData> scheduleWeeklyData = response.WeeklySchedules;
Set<Id> remainingScheduleIds = response.RemainingScheduleIds;
List<pse.ScheduleResourceService.ErrorDetail> errorDetails = response.ErrorDetails;

System.debug('RemainingScheduleIds: ' + remainingScheduleIds);
System.debug('Schedule Weekly Data Size: ' + scheduleWeeklyData.size());
System.debug('Schedule Weekly Data for schedule ID - ' + scheduleWeeklyData[0].ScheduleId + ': ' + scheduleWeeklyData[0]);
System.debug('Schedule Weekly Data for schedule ID - ' + scheduleWeeklyData[1].ScheduleId + ': ' + scheduleWeeklyData[1]);
System.debug('Error Details: ' + errorDetails);

pse.ScheduleResourceService.ScheduleResourceServiceRequest

global inherited sharing class ScheduleResourceServiceRequest

Contains parameters for retrieving weekly scheduled hours information for schedules.

Properties

Name Type Description
ScheduleIds Set<Id> Set of schedule IDs whose weekly scheduled hours information needs to be retrieved.
WeekStartDay pse.CalendarUtil.DayOfWeek [Optional] week's start day. Indicates the week start date. The value of the field is fetched from CollectionUtils class to get a start date for the week. example, CollectionUtils.DayOfWeek.SUNDAY
Values -
• SUNDAY
• MONDAY
• TUESDAY
• WEDNESDAY
• THURSDAY
• FRIDAY
• SATURDAY
If not provided, the value is taken from the Week_Start_Day__c field of Common_Settings__c custom setting and if no value is specified, then 'MONDAY' is considered the default.
StartDate Date [Optional] The start date of the range whose data needs to be retrieved.
If specified, the start date of the overlapping range is considered with the given date and the schedule's start date. If not specified, schedule's start date is considered.
EndDate Date [Optional] The end date of the range whose data needs to be retrieved.
If specified, the end date of the overlapping range is considered with the given date and the schedule's end date. If not specified, schedule's end date is considered.
BatchSize Integer [Optional] The batch size is used to process a limited number of schedule IDs. The remaining schedule IDs are returned as part of the response. as part of the response.
TransactionTimeLimit Integer [Optional] The transaction time limit in milliseconds. If not specified, the CPU time limit of 10 seconds will be used. To process data more quickly, use a lower limit to handle concurrent requests.

Methods

ScheduleResourceServiceRequest

global ScheduleResourceServiceRequest()

pse.ScheduleResourceService.WeeklyScheduleHours

global inherited sharing class WeeklyScheduleHours

Contains information related to the week's start date and scheduled hours associated with it.

Properties

Name Type Description
WeekStartDate Date Week start date of a schedule.
TotalHours Decimal The hours scheduled in a week.

Methods

WeeklyScheduleHours

global WeeklyScheduleHours()

pse.ScheduleResourceService.ScheduleWeeklyData

global inherited sharing class ScheduleWeeklyData

Contains information related to the schedule and weekly scheduled hours associated with it.

Properties

Name Type Description
ScheduleId Id ID of a schedule.
WeeklyScheduleHours List<pse.ScheduleResourceService.WeeklyScheduleHours> Contains information related to week start date and scheduled hours associated to it.

Methods

ScheduleWeeklyData

global ScheduleWeeklyData()

pse.ScheduleResourceService.ErrorDetail

global inherited sharing class ErrorDetail

Contains information about any errors in the process.
If all the Schedule IDs in a request have the same error, then the Schedule IDs field will be empty, and the error field will have an error message. If specific Schedule IDs have errors, then the Schedule IDs field will display those IDs.

Properties

Name Type Description
Error String Contains an error message.
ScheduleIds Set<Id> Set of schedule IDs associated with error.
ErrorType String Specifies the type of error.

Methods

ErrorDetail

global ErrorDetail()

pse.ScheduleResourceService.ScheduleResourceServiceResponse

global inherited sharing class ScheduleResourceServiceResponse

Returns information related to weekly scheduled hours for schedules.

Properties

Name Type Description
WeeklySchedules List<pse.ScheduleResourceService.ScheduleWeeklyData> Contains the list of schedule IDs and weekly scheduled hours associated to it.
RemainingScheduleIds Set<Id> Contains the set of remaining schedule IDs that were not processed. This may be due to CPU time limit, query limit, batch size, or transaction time limit.
ErrorDetails List<pse.ScheduleResourceService.ErrorDetail> Contains information about any errors in the process.

Methods

ScheduleResourceServiceResponse

global ScheduleResourceServiceResponse()

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