Over time your use of Decisions on Demand may generate many policy execution records. To save data storage space you might want to delete them.


We have put together Apex classes that you can schedule to automatically delete old records on a regular basis. Out of the box, the classes allow you to schedule a job which will delete all execution records older than either 7 or 30 days. If you would like to keep records longer, see below under 'Using a custom retention period' for steps to create a job that keeps records for a customer number of days.


NOTE: This functionality is included in Decisions on Demand v1.15 and later. For 1.14 we provide equivalent capabilities as an unmanaged package (please follow this link for details).  


To use the classes:

  • Type 'Apex Class' into the Setup Quick Find box and then select it

            Or go to Setup->Develop->Apex classes in Classic

  • Click 'Schedule Apex'
  • Select one of these two classes:
    • ScheduledCleanExecutionRecords_7: cleans all execution records older than 7 days
    • ScheduledCleanExecutionRecords_30: cleans all execution records older than 30 days
  • Provide a name and select the appropriate time to run the job, such as on the weekend

Note: Setting the Frequency to Weekly or Monthly sets how often the job runs.
The Apex class you choose determines how many days of Policy Execution records you retain.


For additional information on scheduling APEX see this Salesforce help article.

  • Click 'Save'
  • You can verify that the job is scheduled by going to Setup->Environments->Jobs->Scheduled Jobs to see the job is listed:
  • From this screen you can also manage or delete the job


Using a custom retention period

To customize the retention period, you can choose either of the following options:

  • Create and schedule you own subclass of ScheduleCleanExecutionRecords

Call the base class constructor with the number of days you want records to be preserved. For example, to keep records for 180 days the class would look like this:

public class CustomScheduledExecRecordCleaner extends DecsOnD.ScheduledCleanExecutionRecords implements Schedulable {
    public CustomScheduledExecRecordCleaner () {
        super(180);
    }
}

You can then schedule this class as described in the previous section.

  • Instantiate and schedule ScheduledCleanExecutionRecords directly

You can embed a snippet like the following in your code, or execute it using Execute Anonymous

integer retentionPeriod = 180; // Customize to the desired number of days
// For CRON expression format see https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_system.htm#apex_System_System_schedule
String cronExp = ...; // For example: '0 0 2 ? * SUN' is 2am every Sunday
DecsOnD.ScheduledCleanExecutionRecords sched = new DecsOnD.ScheduledCleanExecutionRecords(retentionPeriod);
String jobId = System.schedule('Delete execution records', cronExp, sched);