Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.
  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

share|improve this question

1 Answer 1

up vote 7 down vote accepted

You can do that with the following chron string. This will run every 2 hours. Note that they are set times 2 hours apart.

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

Your Answer

 
discard

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.