You can use the System.schedule method, which takes a cron string to represent the repeating time.
Key is to create string expression that will result in firing every two hours:
Something like:
0 0 1,3,5,7,9,13,15,17,19,21,23 * * ?
Key is to create string expression that will result in firing every four hours:
Something like:
0 0 0,4,8,12,16,20 * * ?
Something like:
0 0 0,4,8,12,16,20 * * ?
So you can create expression to run batch on specific hours as in above example!
Go to dev console and execute code like below, this code will schedule batch for every four hours.
String CRON_EXP = '0 0 0,4,8,12,16,20 * * ?';
testScheduler sch = new testScheduler();
system.schedule('Update job', CRON_EXP, sch);
Nice!
ReplyDelete