Batch job - delete rule evaluation result
Rule Evaluation Result log records are meant for audit purposes and the Banks/FIs clear them on a regular basis. These execution criteria result log records filling up storage space in Salesforce Org as there is no mechanism, other than manual intervention, to delete such records in the system. Also, storage space is a concern in terms of the cost of space.
Now with the August 2023 release, you can execute RuleEvaluationResultCleanupJob to delete the rule evaluation result records ( as these records are filling up the space) from the database. These deleted records are stored in Salesforce's recycle bin and you can restore those as well.
You can define the age of the records that need to be deleted in the custom metadata type Batch_parameters, which is used to configure values of batch parameters. The age parameter determines how old the records should be before deletion.
Prerequisites
None.
Steps
To configure and execute RuleEvaluationResultCleanupJob:
Log in to your Salesforce account.
Select (Setup), and then select Setup.
In the Quick Find box, search for Apex Classes and select it.
-
Select Schedule Apex and perform the following actions, and then select Save:
Note:All the fields are mandatory.
Field name Action Job Name Specify a unique name for the job to identify it Apex Class Search for RuleEvaluationResultCleanupJob and select it. Schedule Apex Execution Frequency Select a frequency based on your requirement. It can be Weekly or Monthly. Start Select a start date for the job End Select an end date for the job Preferred Start Time Select a time when you want to run the job Once the job is scheduled, you can view that on the Scheduled Jobs page (Go to the Quick Find box, search for Scheduled Jobs and select it.).
-
If you want to specify the age of the data to be deleted, perform the following steps:
In the Quick Find box, search for Custom Metadata Types and select it.
Select Manage Records for the Label Batch Parameter.
-
Select Edit for the Label RuleEvaluationResult records cleanup age and specify the age of the data in the Parameter Value field.
Note:If the Parameter Value field is not available in the UI, drag and drop the field by editing the page layout.
This value determines how old the records should be before deletion. The default value is 5 for the Parameter Value field.
-
This parameter is also used by the following batch jobs:
-
To view the status of the job, go to the Quick Find box, search for Apex Jobs and select it.
Note:The job status can be Failed if the records are locked.
To override the configured age parameter, the following parameter can be passed to the class directly:
RuleEvaluationResultCleanupJob job = new RuleEvaluationResultCleanupJob(10, 'Scorecard');
Batch.execute(job);
In the preceding code,
First parameter(10) signifies the age of the records to be deleted
Second parameter (Scorecard) signifies whether to delete the Rule Evaluation Result records from PolicyException or Scorecard.
Age and recordsToBeDeleted parameters are optional.