4
  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.

Thanks

Venkatsforce

1 Answer 1

7

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.

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

You must log in to answer this question.

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