pse.PSATimecardServiceglobal with sharing class PSATimecardService A service that provides functionality relating to Timecards. Methods
submitglobal static pse.PSATimecardService.SubmitResponse submit(pse.PSATimecardService.SubmitRequest request) This method is the preferred way to submit timecards for approval. This method only sets the Status field, typically customizations will be in place to set the Submitted field and actually enter the record into a Salesforce Approval Process. After performing some validations it updates the Status field to Submitted. (This value is customizable through custom setting Timecard Entry UI Global - Timecard submit button action.) The validations performed are:
Input Parameters
Return ValueA response object containing a success flag and potential validation messages. 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. //I have a timecard header that I want to submit. The id is 'a431D00000000snQaH' //Create the request pse.PSATimecardService.SubmitRequest request = new pse.PSATimecardService.SubmitRequest(); request.TimecardIds = new Set<Id>{'a431D00000000snQaH'}; //Call the service to submit pse.PSATimecardService.SubmitResponse response = pse.PSATimecardService.submit(request); //Check the results Map<Id, List<String>> failureReasons = new Map<Id, List<String>>(); for (pse.PSATimecardService.SubmitResult result : response.Results) { if (result.Successful) { //Great, no action required. But you could report the success if necessary. } else { //We need to inform the user why their timecard could not be submitted. //Depending on the use-case we could show messages on the UI, or email or do anything. failureReasons.put(result.TimecardId, result.Errors); } } if (!failureReasons.isEmpty()) { informUser(failureReasons); } saveglobal static pse.PSATimecardService.SaveResponse save(pse.PSATimecardService.SaveRequest request) This method saves the information in the request by creating or updating Timecard_Header__c records and Timecard__c records. It can also create and update records in Task_Time__c when time is being logged on tasks. If some Timecards fail validation or fail with DML errors the other changes will still be saved. The response object provides details about which records failed and why, as well as the Id of newly created Timecards.</p>
These extra validations are performed only when updating timecard records:
If the request is logging time against tasks, a check for duplicate Task Time records is performed; each Timecard can have at most one Task Time linking it to a given Project Task. If this request would create more than that an error is added to the response. Input Parameters
Return ValueA response object containing details about successes and failures. 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. //Prepare the request. The data might come from a custom UI or an external integration. pse.PSATimecardService.TimecardSaveDTO timecard1 = new pse.PSATimecardService.TimecardSaveDTO(); timecard1.ResourceId = '0031D00000ZaGwNQAV'; timecard1.AssignmentId = 'a1U1D000000obR0UAI'; timecard1.ProjectId = 'a2j1D0000008139QAA'; timecard1.StartDate = Date.newInstance(2021, 3, 21); timecard1.EndDate = Date.newInstance(2021, 3, 27); timecard1.MondayHours = 4; pse.PSATimecardService.TimecardSaveDTO timecard2 = new pse.PSATimecardService.TimecardSaveDTO(); timecard2.ResourceId = '0031D00000ZaGwNQAV'; timecard2.AssignmentId = 'a1U1D000000wry8DPE'; timecard2.ProjectId = 'a2j1D0000008139QAA'; timecard2.StartDate = Date.newInstance(2021, 3, 21); timecard2.EndDate = Date.newInstance(2021, 3, 27); timecard2.MondayHours = 4; pse.PSATimecardService.SaveRequest request = new pse.PSATimecardService.SaveRequest(); request.Timecards = new List<pse.PSATimecardService.TimecardSaveDTO>{timecard1, timecard2}; //Call the save pse.PSATimecardService.SaveResponse response = pse.PSATimecardService.save(request); //Handle the response List<Id> newTimecardIds = new List<Id>(); //make a note of new Ids, so we can retrieve them and update them later Boolean allSuccess = true; for (pse.PSATimecardService.SaveResult result : response.Results) { if (result.Successful) { newTimecardIds.add(result.TimecardId); } else { allSuccess = false; //Timecard failed validation or had a DML error. //Check result.Errors, result.DailyErrors for details } } //If there were errors we should report them to the user pse.PSATimecardService.SubmitRequestglobal inherited sharing class SubmitRequest Request object used to submit Timecards. Properties
pse.PSATimecardService.SubmitResponseglobal inherited sharing class SubmitResponse Response object received after calling the submit method. Properties
pse.PSATimecardService.SubmitResultglobal inherited sharing class SubmitResult Contains information on the result of a request to submit a Timecard. Properties
pse.PSATimecardService.SaveRequestglobal inherited sharing class SaveRequest Class contain details of timecards to be saved. Properties
MethodsSaveRequestglobal SaveRequest() pse.PSATimecardService.SaveResponseglobal inherited sharing class SaveResponse A class containing the response from calling save with a SaveRequest. Partial saves are allowed so some results may be successful, while others have failed. Properties
pse.PSATimecardService.SaveResultglobal inherited sharing class SaveResult A class containing the result relating to one timecard. It holds the Id of the timecard if known, if the timecard was saved successfullly, and details of any validation or DML errors. Properties
pse.PSATimecardService.TaskSaveResultglobal inherited sharing class TaskSaveResult Identifier which matches the value set on the TimecardSaveDTO that led to this SaveResult. Useful for matching up SaveResults with TimecardSaveDTO, particularly for phantom records that do not have an ID yet. Properties
pse.PSATimecardService.TimecardSaveDTOglobal inherited sharing class TimecardSaveDTO Contains details of one Timecard to be saved. Properties
MethodsTimecardSaveDTOglobal TimecardSaveDTO() pse.PSATimecardService.TaskTimeSaveDTOglobal inherited sharing class TaskTimeSaveDTO A class containing information for logging time on a task. Properties
MethodsTaskTimeSaveDTOglobal TaskTimeSaveDTO() |