function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Karl TschaepeKarl Tschaepe 

setting batch size on batch apex job

I have a batch job that typically fails due to governor limits. It is running in future state so the limit is often 10001 DML rows. The batch job is called from another scheduled batch job with the line:

System.scheduleBatch(new BatchReconciliation(year, email, false), 'Reconciliation Batch', 1, 200);

The result runs typically 40+ batches but has multiple failures. 

If I change the call to:

System.scheduleBatch(new BatchReconciliation(year, email, false), 'Reconciliation Batch', 1, 20);

it runs over 400 batches, but completes without errors. Is there any drawback to running the job in so many batches? The time for completion seems about the same, but am i flirting with other governor limits?

Thank you!
pconpcon
If you are getting these errors with such a small batch size, you probably do not have optimized code.  There should be no real draw back to running it in so many batches.  The only things you need to keep in mind is
  1. How frequently the batches run.  Is there a chance that the next set of scheduled / batched jobs will run before the previous batch completes.
  2. If there a time restriction on the job. Does this have to occur within a certian time window for the job to be considered valid (ie running every day and it has to finish with the hour).
Richard Fiekowsky 3Richard Fiekowsky 3
Yes, there is a governor limit on how many batches one can run daily. But since the limit is 250,000 per day, you are safe. 
Chandramohan Yetukuri 1Chandramohan Yetukuri 1
Hi,
i had set the batch size of 10 in the scheduler Apex.

global class testschedulerclass implements Schedulable{
    global void execute(SchedulableContext SC) {
        actualBatch b = new actualBatch();
        database.executeBatch(b,10);
    }
}

I scheduled the batch through anonymous window and the batch got failed with the error "Too many callouts: 101".
The same batch job executed successfully after scheduling it from UI. Its bit strange. Can anyone please let me know the reason for the failure...

Regards,
Chandra