Professional Services Automation Apex API Developer Reference

pse.ResourceAssignmentService

global with sharing class ResourceAssignmentService

Contains methods and structures to hold, unhold, and assign resources against resource requests.

Enums

SchedulingStrategy

Value Description
CALCULATE_END_DATE_LEVEL_SCHEDULE Calculates end date respecting availability.
CALCULATE_END_DATE_IGNORE_AVAILABILITY Calculates end date ignoring availability.
ADJUST_DAILY_HOURS Adjusts per day hours based on start date, end date, and total hours.
CALCULATE_END_DATE_CUSTOM_SCHEDULING Use pattern to set hours on each day of week.
PERCENT_ALLOCATION Allocates hours based on the percentage.
ZERO_HOUR_SCHEDULING Creates schedule with zero hours for each day.

Methods

holdResourceRequests

global static List<pse.ResourceAssignmentService.ResourceAssignmentResponse> holdResourceRequests(List<pse.ResourceAssignmentService.ResourceAssignmentRequest> resourceAssignRequests)

Enables you to hold the resources on a resource request. You must have the Resource Request Entry permission control assigned to hold resources.

Input Parameters

Name Type Description
resourceAssignRequests List<pse.ResourceAssignmentService.ResourceAssignmentRequest> List of ResourceAssignmentRequest.

Return Value

Returns the list of pse.ResourceAssignmentService.ResourceAssignmentResponse.

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: Holding a resource on a resource request with resource availability.
    ***************************************************************************************************************************
/*

pse__Resource_Request__c resReq = [SELECT Id, pse__Resource__c, pse__Start_Date__c FROM pse__Resource_Request__c WHERE Id = 'a1nDS000001j8fnYAA'];
pse.ResourceAssignmentService.ResourceAssignmentRequest resAssignRequest = new pse.ResourceAssignmentService.ResourceAssignmentRequest();
resAssignRequest.ResourceRequestId = resReq.Id;
resAssignRequest.ResourceId = resReq.pse__Resource__c;
resAssignRequest.StartDate = resReq.pse__Start_Date__c;
resAssignRequest.Strategy = pse.ResourceAssignmentService.SchedulingStrategy.CALCULATE_END_DATE_LEVEL_SCHEDULE;

List<pse.ResourceAssignmentService.ResourceAssignmentRequest> requestList = new List<pse.ResourceAssignmentService.ResourceAssignmentRequest>{resAssignRequest};

List<pse.ResourceAssignmentService.ResourceAssignmentResponse> responseList = pse.ResourceAssignmentService.holdResourceRequests(requestList);


/*
    ***************************************************************************************************************************
    Example 2: Holding a resource on a resource request with custom start date and level schedule strategy.
    ***************************************************************************************************************************
/*

pse__Resource_Request__c resReq = [SELECT Id, pse__Resource__c FROM pse__Resource_Request__c WHERE Id = 'a1nDS000001j8fnYAA'];
pse.ResourceAssignmentService.ResourceAssignmentRequest resAssignRequest = new pse.ResourceAssignmentService.ResourceAssignmentRequest();
resAssignRequest.ResourceRequestId = resReq.Id;
resAssignRequest.ResourceId = resReq.pse__Resource__c;
resAssignRequest.StartDate = Date.newInstance(2023, 01, 29);
resAssignRequest.Strategy = pse.ResourceAssignmentService.SchedulingStrategy.CALCULATE_END_DATE_LEVEL_SCHEDULE;

List<pse.ResourceAssignmentService.ResourceAssignmentRequest> requestList = new List<pse.ResourceAssignmentService.ResourceAssignmentRequest>{resAssignRequest};

List<pse.ResourceAssignmentService.ResourceAssignmentResponse> responseList = pse.ResourceAssignmentService.holdResourceRequests(requestList);


/*
    ***************************************************************************************************************************
    Example 3: Holding a resource on a resource request with custom hours on week days.
    ***************************************************************************************************************************
/*
Map<String, Decimal> customHours = new Map<String, Decimal>();
customHours.put('mon', 8);
customHours.put('tue', 8);
customHours.put('wed', 8);
customHours.put('thu', 8);
customHours.put('fri', 8);
customHours.put('sat', 4);
customHours.put('sun', 0);

pse__Resource_Request__c resReq = [SELECT Id, pse__Resource__c FROM pse__Resource_Request__c WHERE Id = 'a1nDS000001j8fnYAA'];
pse.ResourceAssignmentService.ResourceAssignmentRequest resAssignRequest = new pse.ResourceAssignmentService.ResourceAssignmentRequest();
resAssignRequest.ResourceRequestId = resReq.Id;
resAssignRequest.ResourceId = resReq.pse__Resource__c;
resAssignRequest.StartDate = Date.newInstance(2023, 01, 29);
resAssignRequest.EndDate = Date.newInstance(2023, 02, 04);
resAssignRequest.Strategy = pse.ResourceAssignmentService.SchedulingStrategy.CALCULATE_END_DATE_CUSTOM_SCHEDULING;
resAssignRequest.CustomHours = customHours;

List<pse.ResourceAssignmentService.ResourceAssignmentRequest> requestList = new List<pse.ResourceAssignmentService.ResourceAssignmentRequest>{resAssignRequest};

List<pse.ResourceAssignmentService.ResourceAssignmentResponse> responseList = pse.ResourceAssignmentService.holdResourceRequests(requestList);

assignResourceRequests

global static List<pse.ResourceAssignmentService.ResourceAssignmentResponse> assignResourceRequests(List<pse.ResourceAssignmentService.ResourceAssignmentRequest> resourceAssignRequests)

This services enables you to create Assignment with the requested resource on the Resource Request. You must have the Resource Request Entry and Staffing permission control assigned to create assignments. If scheduling strategy is not defined and the UseDefaultStrategy field is selected, then scheduling strategy is retrieved from the Default Scheduling Strategy field of the Assignment Settings custom setting. If Default Scheduling Strategy field is blank, then the 'Calculate End Date, Level Schedule' strategy will be used.

Input Parameters

Name Type Description
resourceAssignRequests List<pse.ResourceAssignmentService.ResourceAssignmentRequest> List of ResourceAssignmentRequest.

Return Value

Returns the list of pse.ResourceAssignmentService.ResourceAssignmentResponse.

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: Create an Assignment from a Resource Request, respecting the resource's availability.
    ***************************************************************************************************************************
/*

pse__Resource_Request__c resReq = [SELECT Id, pse__Staffer_Resource__c, pse__Start_Date__c FROM pse__Resource_Request__c WHERE pse__Resource_Held__c = true AND Id = 'a1nDS000001j8fnYAA'];
pse.ResourceAssignmentService.ResourceAssignmentRequest resAssignRequest = new pse.ResourceAssignmentService.ResourceAssignmentRequest();
resAssignRequest.ResourceRequestId = resReq.Id;
resAssignRequest.ResourceId = resReq.pse__Staffer_Resource__c;
resAssignRequest.StartDate = resReq.pse__Start_Date__c;
resAssignRequest.Strategy = pse.ResourceAssignmentService.SchedulingStrategy.CALCULATE_END_DATE_LEVEL_SCHEDULE;

List<pse.ResourceAssignmentService.ResourceAssignmentRequest> requestList = new List<pse.ResourceAssignmentService.ResourceAssignmentRequest>{resAssignRequest};

List<pse.ResourceAssignmentService.ResourceAssignmentResponse> responseList = pse.ResourceAssignmentService.assignResourceRequests(requestList);


/*
    ***************************************************************************************************************************
    Example 2: Create an Assignment from a Resource Request with custom start date and level schedule strategy.
    ***************************************************************************************************************************
/*

pse__Resource_Request__c resReq = [SELECT Id, pse__Staffer_Resource__c FROM pse__Resource_Request__c WHERE pse__Resource_Held__c = true AND Id = 'a1nDS000001j8fnYAA'];
pse.ResourceAssignmentService.ResourceAssignmentRequest resAssignRequest = new pse.ResourceAssignmentService.ResourceAssignmentRequest();
resAssignRequest.ResourceRequestId = resReq.Id;
resAssignRequest.ResourceId = resReq.pse__Staffer_Resource__c;
resAssignRequest.StartDate = Date.newInstance(2023, 01, 29);
resAssignRequest.Strategy = pse.ResourceAssignmentService.SchedulingStrategy.CALCULATE_END_DATE_LEVEL_SCHEDULE;

List<pse.ResourceAssignmentService.ResourceAssignmentRequest> requestList = new List<pse.ResourceAssignmentService.ResourceAssignmentRequest>{resAssignRequest};

List<pse.ResourceAssignmentService.ResourceAssignmentResponse> responseList = pse.ResourceAssignmentService.assignResourceRequests(requestList);


/*
    ***************************************************************************************************************************
    Example 3: Create an Assignment from a Resource Request with custom hours on week days.
    ***************************************************************************************************************************
/*
Map<String, Decimal> customHours = new Map<String, Decimal>();
customHours.put('mon', 8);
customHours.put('tue', 8);
customHours.put('wed', 8);
customHours.put('thu', 8);
customHours.put('fri', 8);
customHours.put('sat', 4);
customHours.put('sun', 0);

pse__Resource_Request__c resReq = [SELECT Id, pse__Staffer_Resource__c FROM pse__Resource_Request__c WHERE pse__Resource_Held__c = true AND Id = 'a1nDS000001j8fnYAA'];
pse.ResourceAssignmentService.ResourceAssignmentRequest resAssignRequest = new pse.ResourceAssignmentService.ResourceAssignmentRequest();
resAssignRequest.ResourceRequestId = resReq.Id;
resAssignRequest.ResourceId = resReq.pse__Staffer_Resource__c;
resAssignRequest.StartDate = Date.newInstance(2023, 01, 29);
resAssignRequest.EndDate = Date.newInstance(2023, 02, 04);
resAssignRequest.Strategy = pse.ResourceAssignmentService.SchedulingStrategy.CALCULATE_END_DATE_CUSTOM_SCHEDULING;
resAssignRequest.CustomHours = customHours;

List<pse.ResourceAssignmentService.ResourceAssignmentRequest> requestList = new List<pse.ResourceAssignmentService.ResourceAssignmentRequest>{resAssignRequest};

List<pse.ResourceAssignmentService.ResourceAssignmentResponse> responseList = pse.ResourceAssignmentService.assignResourceRequests(requestList);

/*
    ***************************************************************************************************************************
    Example 4: Create an assignment from a resource request with strategy from the Default Scheduling Strategy field of the Assignment Settings custom setting.
    * UseDefaultStrategy flag is used to get scheduling strategy from the Default Scheduling Strategy field of the Assignment Settings custom setting.
    ***************************************************************************************************************************
/*

pse__Resource_Request__c resReq = [SELECT Id, pse__Staffer_Resource__c, pse__Start_Date__c FROM pse__Resource_Request__c WHERE pse__Resource_Held__c = true AND Id = 'a1nDS000001j8fnYAA'];
pse.ResourceAssignmentService.ResourceAssignmentRequest resAssignRequest = new pse.ResourceAssignmentService.ResourceAssignmentRequest();
resAssignRequest.ResourceRequestId = resReq.Id;
resAssignRequest.ResourceId = resReq.pse__Staffer_Resource__c;
resAssignRequest.StartDate = resReq.pse__Start_Date__c;
resAssignRequest.UseDefaultStrategy = true;

List<pse.ResourceAssignmentService.ResourceAssignmentRequest> requestList = new List<pse.ResourceAssignmentService.ResourceAssignmentRequest>{resAssignRequest};

List<pse.ResourceAssignmentService.ResourceAssignmentResponse> responseList = pse.ResourceAssignmentService.assignResourceRequests(requestList);

unholdResourceRequests

global static List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignResponse> unholdResourceRequests(List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest> resourceUnholdRequests)

Enables you to update the provided resource requests to unhold by updating the fields of the resource request. You must have the Resource Request Entry permission control assigned to hold resources. If an error occurs while processing any resource request, updates to other resource requests are rolled back and an error is returned.

Input Parameters

Name Type Description
resourceUnholdRequests List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest> List of request wrappers containing a Resource Request ID which should have resource and schedule linked and Status to be updated after unhold.

Return Value

Returns the list of pse.ResourceAssignmentService.ResourceUnholdOrUnassignResponse.

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.

/*
 * Unholding resources on resource requests.
/*
List<pse__Resource_Request__c> heldResourceRequests = [SELECT Id FROM pse__Resource_Request__c WHERE pse__Resource_Held__c = true AND pse__Project__c = 'a1o6s000000uu0SAAQ' LIMIT 2];

pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest resourceUnholdRequest1 = new pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest();
resourceUnholdRequest1.ResourceRequestId = heldResourceRequests[0].Id;
resourceUnholdRequest1.Status = 'Ready to Staff';

pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest resourceUnholdRequest2 = new pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest();
resourceUnholdRequest2.ResourceRequestId = heldResourceRequests[1].Id;
resourceUnholdRequest2.Status = 'Draft';

List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest> resourceUnholdRequests = new List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest>{resourceUnholdRequest1, resourceUnholdRequest2};

List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignResponse> resourceUnholdResponses = pse.ResourceAssignmentService.unholdResourceRequests(resourceUnholdRequests);
Id unheldResourceRequestId1 = resourceUnholdResponses[0].ResourceRequestId;
Id unheldResourceRequestId2 = resourceUnholdResponses[1].ResourceRequestId;

unassignResourceRequests

global static List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignResponse> unassignResourceRequests(List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest> resourceUnassignRequests)

Updates the provided resource requests to unassign by updating the fields of the resource request. If an error occurs when unassigning any resource request, the process is rolled back and an error is returned.

Input Parameters

Name Type Description
resourceUnassignRequests List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest> List of request wrapper containing a Resource Request ID. The ID should be linked to assignments and schedules, and the status should be updated after unassigning.

Return Value

Pse.ResourceAssignmentService.ResourceUnholdOrUnassignResponse.

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.

/*
 * Unassigning resources on resource requests.
/*

List<pse__Resource_Request__c> assignedResourceRequests = [SELECT Id FROM pse__Resource_Request__c WHERE pse__Assignment__c != NULL AND pse__Project__c = 'a1o6s000000uu0SAAQ' LIMIT 2];
pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest resourceUnassignRequest1 = new pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest();
resourceUnassignRequest1.ResourceRequestId = assignedResourceRequests[0].Id;
resourceUnassignRequest1.Status = 'Ready to Staff';

pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest resourceUnassignRequest2 = new pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest();
resourceUnassignRequest2.ResourceRequestId = assignedResourceRequests[1].Id;
resourceUnassignRequest2.Status = 'Draft';

List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest> resourceUnassignRequests = new List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest>{resourceUnassignRequest1, resourceUnassignRequest2};

List<pse.ResourceAssignmentService.ResourceUnholdOrUnassignResponse> resourceUnassignResponses = pse.ResourceAssignmentService.unassignResourceRequests(resourceUnassignRequests);
Id unassignResourceRequestId1 = resourceUnassignResponses[0].ResourceRequestId;
Id unassignResourceRequestId2 = resourceUnassignResponses[1].ResourceRequestId;

pse.ResourceAssignmentService.ResourceAssignmentRequest

global with sharing class ResourceAssignmentRequest

Contains parameters for holding a resource on a resource request or assigning a resource request to a resource. The CustomHours and PercentAlloc fields are required for the CALCULATE_END_DATE_CUSTOM_SCHEDULING and PERCENT_ALLOCATION scheduling strategies, respectively.

Properties

Name Type Description
ResourceRequestId Id Resource Request ID for creating or holding assignments for a resource.
ResourceId Id Resource ID for holding resource requests or assigning on assignments.
StartDate Date Start date for the schedule.
EndDate Date End date for the schedule.
Strategy pse.ResourceAssignmentService.SchedulingStrategy Strategy for schedule calculation. Additional properties may be required depending on the chosen strategy.
CustomHours Map<String, Decimal> Hours for each day when custom scheduling strategy is selected.
PercentAlloc Decimal Percentage to create a schedule when the percent allocation scheduling strategy is selected.
UseDefaultStrategy Boolean The flag is used to get scheduling strategy from the Default Scheduling Strategy field of the Assignment Settings custom setting.

pse.ResourceAssignmentService.ResourceAssignmentResponse

global with sharing class ResourceAssignmentResponse

Returns information related to the resource request ID and resource ID.

Properties

Name Type Description
ResourceRequestId Id Resource Request ID for creating or holding assignments for a resource.
Resource Id Resource ID for holding resource requests or assigning on assignments.

pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequest

global with sharing class ResourceUnholdOrUnassignRequest

Contains parameters for unholding or unassigning the resource on a resource request.

Properties

Name Type Description
ResourceRequestId Id Resource Request ID for unholding or unassigning resource on resource requests.
Status String Status value of the resource request after unhold. If the status is blank, the default value is Draft.

Methods

ResourceUnholdOrUnassignRequest

global ResourceUnholdOrUnassignRequest()

pse.ResourceAssignmentService.ResourceUnholdOrUnassignResponse

global with sharing class ResourceUnholdOrUnassignResponse

Returns information related to the resource request.

Properties

Name Type Description
ResourceRequestId Id The ID of the target resource request.
ErrorMessage String Contains any errors from unholding or unassigning the resource.
© Copyright 2009–2024 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.