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
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 ? * *';
-
Thanks for your quick response. What is the syntax to run all days of the week ? Commented Sep 17, 2013 at 18:15
-
-
-