11

I have a requirement where i need to run an apex batch job every 4 hours daily monday to friday and all months in a year. I looked at the apex cron job documentation to be setup using code snippets in execute anonymous window. But it is not very clear. I am not sure whether i can do this through the gui but i would like to atleast do this through the system.schedule at run time is fine. Could you guys give me exact syntax for the cron please?

2 Answers 2

24

If you use the following chron string for your scheduled job, it will run every 4 hours (at set times) Monday through Friday.

apexScheduledJob j = new apexScheduledJob ();
String sch = '0 0 0,4,8,12,16,20 ? * MON-FRI';
System.schedule('My Job', sch, j);

If you wanted it to run every day, you would just change it to

String sch = '0 0 0,4,8,12,16,20 ? * *';
4
  • Thanks for your quick response. What is the syntax to run all days of the week ? Sep 17, 2013 at 18:15
  • Updated the answer to reflect Sep 17, 2013 at 18:17
  • No prob. Glad it helped Sep 17, 2013 at 18:25
  • Curiously, the V44 doc says you can't use commas in the hours place for the Cron expression yet it works
    – cropredy
    Nov 22, 2018 at 0:16
3

use this site to make cron for every scenario. cronmaker

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .