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.




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.

  • 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? May 9 '14 at 5:25
  • Yes that should work May 9 '14 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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