2

I want to schedule a batch to run everyday at 1 am. I've tried the following code as suggested here:

System.schedule('BatchAccount daily at 5 am', '0 0 1 * * ?', new BatchAccount());

But if I view the details of my scheduled job from the UI I see this:

Job Schedule

What I am doing wrong?

2

Just schedule your job through the UI if you are doing something simple like every day at a specific time. Using system.schedule makes things needlessly complex.

Steps To Schedule

  1. Make sure your Apex Class implements the Schedulable interface.
  2. Navigate to Setup > Develop > Apex Classes.
  3. Click the Schedule Apex button.
  4. Select your Apex Class.
  5. Set the schedule you desire.
  6. Click the Save button.

See also: Schedule Apex.

  • 1
    Yeah, you should only use cron for complex scheduling. I see it all the time on here. – Adrian Larson Aug 24 '16 at 13:40
  • 1
    Nice wearing of the admin hat, using the tools is way preferable! – bigassforce Aug 24 '16 at 13:45
  • As long as you remember to schedule the job every few months after it expires. – sfdcfox Aug 24 '16 at 14:26
2

The cron string is correct. The limitation is the GUI configuration screen. It can't correct express any but the most simple of configurations. Your job will run as expected, however.

  • 1
    Just curious, do you disagree that using system.schedule is overkill for a job running at the same time every day? My opinion is Clicks Not Code holds strongly here. – Adrian Larson Aug 24 '16 at 13:43
  • 'Your job will run as expected, however.' I dont know about that... – tony danza Aug 24 '16 at 14:09
  • @AdrianLarson I generally do agree with "clicks over code." However, assuming you want a daily schedule to run for all time, you need code, not clicks. Or, if you want your schedule to run every four hours... etc. The GUI is intentionally restricted, so you need to use code for some types of schedules. – sfdcfox Aug 24 '16 at 14:25
  • You can set an end date way in the future through the UI. I've definitely set it more than 10 years out. If you're really worried about it, you could set it much further than that. Not as good as forever, true. Still, I opt for simplicity here. – Adrian Larson Aug 24 '16 at 14:26

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.