Schedule Audits via Apex
- 13 Jul 2022
- 1 Minute to read
- Print
- DarkLight
Schedule Audits via Apex
- Updated on 13 Jul 2022
- 1 Minute to read
- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback
- 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);
}
}
From Setup, enter Apex Classes in the Quick Find box, select Apex Classes, and then click Schedule Apex.
Specify the name of a class that you want to schedule (i.e. "ScheduleAudit").
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).
Specify the start and end dates for the Apex scheduled class. If you specify a single day, the job only runs once.
Specify a preferred start time. The exact time the job starts depends on service availability.
Click Save.