The saveRH Global Method

The saveRH global method allows you to save Resource Forecast data as if it had been saved directly from a Resource Hero matrix.  This logic will save data while managing the relationship between Forecasts, Actuals, and other Resource Hero matrix enabled fields.

Signature

global static String saveRH(List<String> assignments, String startdate, String enddate, String viewby, String AorF, Map<String, String> data) {

Parameters

NameDescriptionTypeFormatAvailable Options
assignmentsA list of Resource Assignment record Ids.  For any forecast record that is going to be inserted/updated by this method, the related assignment id must be provided in this list.List<String>
startdateThe earliest forecast date that will be updated as part of this call.StringYYYY-MM-DD
enddateThe latest forecast date that will be updated as part of this call.StringYYYY-MM-DD
viewbyControls how hours will be spread across work days or weeks.  In most cases where you are sending in specific updates to Resource Hero based on some external data source, this should be set to Day.StringDay
Week
Month
AorFDescribes the matrix-enabled field that you are trying to save.StringForecast
Actual

If enabled, other matrix enabled fields controlled by the RHA Matrix Enabled Fields custom setting
dataThis map contains the data that you are trying to insert, update or delete.Map<String, String>key is a concatenation of the resource assignment name, a dash, and the date.  Example:  ARN202-2020-08-01

value is a string representation of the value that is being saved.  Example:  34.3

Return Value

The saveRH global method will return one of the following values of type String

ValueDescription
success_syncData was successfully processed and saved to the database synchronously.
success_asyncDescription: Data was successfully processed, but due to the number of records, the save operation has been sent to a batch job for processing.  The user who initiated the save will be notified via email when the save completes.
jidxxxxxxxxxxxxxxxxxxDue to a large number of saves, initial processing has been sent to a queueable with job id xxxxxxxxxxxxxxxxxx

Example

//Variables used to find the example assignment
 Id resourceid = 'a050L00000g7NM9QAM'; //replace with a valid resource id
 Id oppid = '0064W00000tgfuHQAQ'; //replace with a valid opportunity id
 String AorF = 'Actual';
 String viewby = 'Day';
 
 //Get the assignment that we need to update
 ResourceHeroApp__Resource_Assignment__c ras = [SELECT Id, Name
 FROM ResourceHeroApp__Resource_Assignment__c
 WHERE ResourceHeroApp__Resource__c = :resourceid
 AND ResourceHeroApp__Opportunity__c = :oppid
 LIMIT 1];
 
 //Add all assignment ids to a list
 List<String> assignments = new List<String>();
 assignments.add(ras.Id);
 
 //Build our data mapping for each date
 Map<String, String> data = new Map<String, String>();
 data.put(ras.Name + '-' + '2020-08-03', '8');
 data.put(ras.Name + '-' + '2020-08-10', '7');
 data.put(ras.Name + '-' + '2020-08-17', '9');
 data.put(ras.Name + '-' + '2020-08-24', '8');
 
 //Ensure our start and end date variables are set appropriately
 String startdate = '2020-08-03';
 String enddate = '2020-08-24';
 
 //Send to the method for save
 String result = ResourceHeroApp.MatrixController.saveRH(assignments, startdate, enddate, viewby, AorF, data);
 
 //Confirm success
 system.assertEquals('success_sync', result);

Related Support Posts:

Ready to get started?

Schedule a call to see if Resource Hero is right for you

Book now