Schedule Audits via Apex
  • 13 Jul 2022
  • 1 Minute to read
  • Dark
    Light

Schedule Audits via Apex

  • Dark
    Light

Article summary

  1. Create a Schedulable Interface using the following example to call the Compliance namespace.
global class ScheduleAudit implements Schedulable {
  global void execute(SchedulableContext sc){
    String objectName = 'Case'; // or pass another object name
    pcify__Manager__mdt manager = pcify.Manager.getManager(objectName);

    pcify.Batch batchJob = new pcify.Batch();
    batchJob.objectName = manager.MasterLabel;
    batchJob.fieldNames = manager.pcify.Manager.getMaskFields(objectName);
    batchJob.startDate = manager.pcify__BatchStartDate__c; // or pass your own datetime value
    batchJob.endDate = manager.pcify__BatchEndDate__c; // or pass your own datetime value
    batchJob.filterField = manager.pcify__BatchFilterField__c;
    batchJob.queryLimit = Integer.valueOf(manager.pcify__BatchQueryLimit__c);
    batchJob.batchSize = Integer.valueOf(manager.pcify__BatchSize__c);
    batchJob.action = manager.pcify__AuditAction__c;
    batchJob.loadQuery();
    database.executebatch(batchJob, batchJob.batchSize);
  }
}
  1. From Setup, enter Apex Classes in the Quick Find box, select Apex Classes, and then click Schedule Apex.
    schedulde audits

  2. Specify the name of a class that you want to schedule (i.e. "ScheduleAudit").

  3. Specify how often the Apex class is to run.

    • For Weekly—specify one or more days of the week the job is to run (such as Monday and Wednesday).
    • For Monthly—specify either the date the job is to run or the day (such as the second Saturday of every month).
  4. Specify the start and end dates for the Apex scheduled class. If you specify a single day, the job only runs once.

  5. Specify a preferred start time. The exact time the job starts depends on service availability.

  6. Click Save.
    audit specifics