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
Name | Description | Type | Format | Available Options |
---|---|---|---|---|
assignments | A 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> | ||
startdate | The earliest forecast date that will be updated as part of this call. | String | YYYY-MM-DD | |
enddate | The latest forecast date that will be updated as part of this call. | String | YYYY-MM-DD | |
viewby | Controls 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. | String | Day Week Month | |
AorF | Describes the matrix-enabled field that you are trying to save. | String | Forecast Actual If enabled, other matrix enabled fields controlled by the RHA Matrix Enabled Fields custom setting | |
data | This 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
Value | Description |
---|---|
success_sync | Data was successfully processed and saved to the database synchronously. |
success_async | Description: 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. |
jidxxxxxxxxxxxxxxxxxx | Due 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);