pse.ResourceAssignmentServiceglobal with sharing class ResourceAssignmentService Contains methods and structures to hold, unhold, and assign resources against resource requests. EnumsSchedulingStrategy
Methods
holdResourceRequestsglobal 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
Return ValueReturns 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); assignResourceRequestsglobal 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
Return ValueReturns 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); unholdResourceRequestsglobal 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
Return ValueReturns 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; unassignResourceRequestsglobal 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
Return ValuePse.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.ResourceAssignmentRequestglobal 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
pse.ResourceAssignmentService.ResourceAssignmentResponseglobal with sharing class ResourceAssignmentResponse Returns information related to the resource request ID and resource ID. Properties
pse.ResourceAssignmentService.ResourceUnholdOrUnassignRequestglobal with sharing class ResourceUnholdOrUnassignRequest Contains parameters for unholding or unassigning the resource on a resource request. Properties
MethodsResourceUnholdOrUnassignRequestglobal ResourceUnholdOrUnassignRequest() pse.ResourceAssignmentService.ResourceUnholdOrUnassignResponseglobal with sharing class ResourceUnholdOrUnassignResponse Returns information related to the resource request. Properties
|