Sunday 6 December 2020

FinServ Optimize Record Rollups: Sample Apex Code on how to use HouseholdAssignmentBatchable batch job.


A sample code on how to use HouseholdAssignmentBatchable class from the anonymous window.


One you enabled Optimised Roll-ups with Winter 21 - Optimize Record Rollups
And as per this article: https://help.salesforce.com/articleView?id=release-notes.rn_fsc_rollup_config_custom_setting.htm&type=5&release=228

If you enabled the new Record Rollup Optimization (Beta) org preference, use the new HouseholdAssignmentBatchable batch job instead of GroupAssignmentBatchable to roll up records in batches.




Below is a sample code to how to run the HouseholdAssignmentBatchable batch job:



Option 1

To execute the job for a single object with configuration defined in the custom setting use the following signature

FinServ.HouseholdAssignmentBatchable.runJob('Task');

Option 2

To execute the job for multiple objects sequentially with configuration defined in the custom setting use the following signature



FinServ.HouseholdAssignmentBatchable.runJob(new List<String> {'FinancialAccount__c', 'Task'});

 Option 3

To execute the job for one or more objects with overridden settings,  New instances of class FinServ.HouseholdAssignmentBatchable.RecordRollupConfig need to be constructed and passed to FinServ.HouseholdAssignmentBatchable.runJob(List<FinServ.HouseholdAssignmentBatchable.RecordRollupConfig> recordRollupConfigs).


FinServ.HouseholdAssignmentBatchable.RecordRollupConfig provides two constructors:

//startTime, endTime can be set to null.
//When set to null that filter is not applied when querying the object.

//Constructor 1:
RecordRollupConfig(String objectName, Datetime startTime, Datetime endTime)

//Constructor 2:
RecordRollupConfig(String objectName, Datetime startTime, Datetime endTime, Integer scope)



Sample code.


FinServ.HouseholdAssignmentBatchable.RecordRollupConfig recordRollupConfigFinancialAccount = new FinServ.HouseholdAssignmentBatchable.RecordRollupConfig('FinancialAccount__c', DateTime.newInstance(2009, 3, 4, 21, 2, 2), null, 500);

FinServ.HouseholdAssignmentBatchable.RecordRollupConfig recordRollupConfigCase = new FinServ.HouseholdAssignmentBatchable.RecordRollupConfig('Case', null, null);

List<FinServ.HouseholdAssignmentBatchable.RecordRollupConfig> recordRollupConfigs = new List<FinServ.HouseholdAssignmentBatchable.RecordRollupConfig>{recordRollupConfigFinancialAccount, recordRollupConfigCase};

FinServ.HouseholdAssignmentBatchable.runJob(recordRollupConfigs);

// Note: To run concurrently for multiple objects you can call FinServ.HouseholdAssignmentBatchable.runJob() multiple times.
// For example, see the sample below.

FinServ.HouseholdAssignmentBatchable.runJob('Task');
FinServ.HouseholdAssignmentBatchable.runJob('Claim');


            

No comments:

Post a Comment

How to generate QR code for Survey Invitation in Salesforce Platform Survey

 Easy steps to generate QR code for Survey Invitation Link 1) Create your Survey using Salesforce Platform Survey. 2) Once done activate it....