Recurring Scheduling Apex Job for every 10,15 etc minutes


Hi All,
I was just trying to schedule my job for every 15 minute by executing below code. But the job was running once only and it was not triggering again.
Schedular_GlobalAppLogPurgeBatch globalPurgeBatchSchedular = new Schedular_GlobalAppLogPurgeBatch();
System.schedule('Global App Logs Purge1', '0 0 15 * * ? *', globalPurgeBatchSchedular);

Then  i came to know that Jobs cannot be scheduled in increments smaller than one hour. To schedule the job fro every 15 minute, i have to do the following
Schedular_GlobalAppLogPurgeBatch globalPurgeBatchSchedular = new Schedular_GlobalAppLogPurgeBatch();
System.schedule('Global App Logs Purge1', '0 0 * * * ? *', globalPurgeBatchSchedular);
System.schedule('Global App Logs Purge2', '0 15 * * * ? *', globalPurgeBatchSchedular);
System.schedule('Global App Logs Purge3', '0 30 * * * ? *', globalPurgeBatchSchedular);
System.schedule('Global App Logs Purge4', '0 45 * * * ? *', globalPurgeBatchSchedular);

So conclusion is that if you want to schedule for less than hour, you should use below formula.
No of System.schedule() call = 60/frequency in minutes;

e.g. For 10 minutes, please run:
No of System.schedule() call :  60/10 = 6

Schedular_GlobalAppLogPurgeBatch globalPurgeBatchSchedular = new Schedular_GlobalAppLogPurgeBatch();
System.schedule('Global App Logs Purge1', '0 0 * * * ? *', globalPurgeBatchSchedular);
System.schedule('Global App Logs Purge2', '0 10 * * * ? *', globalPurgeBatchSchedular);
System.schedule('Global App Logs Purge3', '0 20 * * * ? *', globalPurgeBatchSchedular);
System.schedule('Global App Logs Purge4', '0 30 * * * ? *', globalPurgeBatchSchedular);
System.schedule('Global App Logs Purge5', '0 40 * * * ? *', globalPurgeBatchSchedular);
System.schedule('Global App Logs Purge6', '0 50 * * * ? *', globalPurgeBatchSchedular);

I hope this will help you.

Comments

Popular posts from this blog

System.AsyncException: The Apex job named is already scheduled for execution.

Custom Setting Creation in Apex Test Class

Error : "Trigger must be associated with a job detail"

AJAX Toolkit Debug Shell

Salesforce Trace Log Query Using Apex

how to get object name from id / prefix value in salesforce

How to Query All the batch classes in your Salesforce Instance using APEX

Creating Salesforce Developer Account

Creating MAP from SOQL Query

Custom Pagination Without Controller (Apex)