3

I am curious to know is there any notable difference between Database.executeBatch vs System.scheduleBatch. One difference I know is, we can delay the batch execution in scheduleBatch method. However, I did not find any performance related documents.

Anyone have experienced any performance difference with these methods?

6

The performance of all Batch Apex (all asynchronous Apex, really) can vary based on system load. That applies regardless of whether the batch is enqueued immediately or with a time delay, based on the load when execution actually happens.

The extra wrinkle with System.scheduleBatch() is that scheduled job limits apply at the time of scheduling, while normal batch Apex limits are applied once the schedule fires and enqueues the batch job:

All scheduled Apex limits apply for batch jobs scheduled using System.scheduleBatch. After the batch job is queued (with a status of Holding or Queued), all batch job limits apply and the job no longer counts toward scheduled Apex limits.

You also don't have to implement Schedulable in your batch class if you're only using one-off scheduling with System.scheduleBatch().

| improve this answer | |
  • Thanks David! Which one you'd recommend to use,? – Ysr Shk Jun 4 '18 at 15:35
  • 1
    Use Database.executeBatch() unless you specifically need to delay the execution of the batch class. I never use System.scheduleBatch() myself. – David Reed Jun 4 '18 at 15:40

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.