Reprocess all rollups

When adding new rollup fields to Resource Hero, you may need to reprocess all rollups so that historical records are reflected accurately.

The below script will query all existing resource assignments and add their related records to the asynchronous queue for reprocessing.  Finally, it will execute the rollup batch process.

Note:  When rollup fields on a related record are updated, any automation such as Process Builder processes, Flows, Workflows, and Triggers on the related records will be executed as well.  As a best practice, ensure that appropriate criteria are added to automation so that they execute only as needed.

//Query all assignment related record ids
List<AggregateResult> ras_agg = [select ResourceHeroApp__relatedId__c
    FROM ResourceHeroApp__Resource_Assignment__c
    GROUP BY ResourceHeroApp__relatedId__c];
 
 
 //Add an entry into the rha async queue
List<ResourceHeroApp__RHA_Async_Queue__c> aqs_forinsert = new List<ResourceHeroApp__RHA_Async_Queue__c>();
for(AggregateResult ra_agg : ras_agg) {
   Id currentid = Id.valueOf(String.valueOf(ra_agg.get('ResourceHeroApp__relatedId__c')));
   aqs_forinsert.add(new ResourceHeroApp__RHA_Async_Queue__c(
       ResourceHeroApp__Target_Id__c = currentid,
       ResourceHeroApp__Target_SobjectType__c = String.valueOf(currentid.getSobjectType()),
       ResourceHeroApp__Operation__c = 'Rollup',
       ResourceHeroApp__Target_Id_Operation__c = currentid + ' - Rollup'));
}
 
//Insert async queue records
Database.SaveResult[] insert_aqs = Database.Insert(aqs_forinsert, false);
 
//Execute the rollup batch process
ResourceHeroApp.RHA_Batch_ProcessRollups pr = new ResourceHeroApp.RHA_Batch_ProcessRollups();
database.executebatch(pr);

Going forward, rollups are automatically reprocessed any time Resource Assignment and Resource Forecast records are updated, whether within the matrix, time tracking lightning component, or through the native salesforce user interface.

Related Support Posts:

Ready to get started?

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

Book now