Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  How to schedule the batch for every two hours per day? 
  I try like this 

   String schedule = '0 0 1/2 * * ?';
   System.schedule('Jobname',schedule,new SampleTracking());

but i don't know it is corrrect or not.I execute it in developer console it shows the start time as after 2hours from the current time.



share|improve this question
up vote 7 down vote accepted

You can do that with the following cron string.

apexScheduledJob myJob = new apexScheduledJob ();
String sch = '0 0 0,2,4,6,8,10,12,14,16,18,20,22 ? * *';
System.schedule('My Job', sch, myJob);

This job will run every 2 hours, at the top of the hour, starting at midnight.

share|improve this answer
Thanks for your assistance @sfdc_ninja.. – Venkatsforce May 8 '14 at 13:51
If i want to run the batch in particular times like 12 AM(midnight),8 AM, 4 PM but i schedule the batch like this String schedule = '0 0 0,8,16 * * ?'; System.schedule('My Job', schedule , new myJob()); Is this correct? – Venkatsforce May 9 '14 at 5:25
Yes that should work – Chris Duncombe May 9 '14 at 11:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.