2

Just a quick query on Batch Apex.

Let us say I have about 8000 Opportunity records to process in our nightly batch job.

The objective of this batch is to update a field on Opportunity if it matches certain condition.

I want the number of records in each "chunk" (batch) to be around 100 which I will indicate in my scope parameter.

So that puts me to 80 batches to be processed and I believe Gov Limits will be applicable within each batch.

There are two records A & B which will cause validation errors when they are getting updated.

Assume they are in Batch #1 (Record A) and Batch # 71 (Record B) out of 80 batches.

Now

a)

Record A from Batch #1 fails the DML.

Will this cause the entire batch job to fail or only that particular record in Batch # 1 to fail and other records will proceed as usual or the entire batch of Batch #1 will fail ?

b)

Will the other batches (Batch #2 to Batch #70, Batch #72 to Batch #80) proceed for processing ?

2 Answers 2

4

a) It depends on what DML methods you are using

i)Using Database.Upsert will allow you to continue processing all other records of the Batch without failing anything .You have an optional parameter to decide whether you want to fail all records of the batch or continue

Database.update(list, false)

If you just use normal DML like insert ,then lets say a record fails in Batch 1 then only batch 1 will fail while rest will succeed if there are no failures

b)Yes they will proceed inspite of a single batch failure

1

Record A from Batch #1 fails the DML.

Will this cause the entire batch job to fail or only that particular record in Batch # 71 to fail and other records will proceed as usual or the entire batch of Batch #1 will fail ?

it will stop the 1st batch execution from 80 jobs means entire Batch #1 will fail.

Will the other batches (Batch #2 to Batch #70, Batch #72 to Batch #80) proceed for processing ?

Yes it will executes successfully if no error occurs from Batch #2 to Batch #70

I suggest use Database.update(list, false) for updating records if only one record is fault then only that record will fail and all other records in same batch will execute successfully.

You must log in to answer this question.

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