Exceptions that arise from a bulk DML call (including any recursive
DML operations in triggers that are fired as a direct result of the
call) are handled differently depending on where the original call
came from:
- When errors occur because of a bulk DML call that originates directly from the Apex DML statements, or if the
allOrNone parameter of a Database DML method was specified as true, the runtime engine follows the “all or
nothing” rule: during a single operation, all records must be updated successfully or
the entire operation rolls back to the point immediately preceding the DML statement.
- When errors occur because of a bulk DML call that originates from the SOAP API with default settings, or if
the allOrNone parameter of a Database DML method was specified as false, the runtime engine attempts at least a partial save:
- During the first attempt, the runtime engine processes all records. Any record that
generates an error due to issues such as validation rules or unique index violations is set
aside.
- If there were errors during the first attempt, the runtime engine makes a second attempt
that includes only those records that did not generate errors. All records that didn't
generate an error during the first attempt are processed, and if any record generates an
error (perhaps because of race conditions) it is also set aside.
- If there were additional errors during the second attempt, the runtime engine makes a
third and final attempt which includes only those records that didn’t generate errors during
the first and second attempts. If any record generates an error, the entire operation fails
with the error message, “Too many batch retries in the presence of Apex triggers and partial
failures.”