According to Bulk DML Exception Handling :

Apex triggers are fired for the first save attempt, and if errors are encountered for some records and subsequent attempts are made to save the subset of successful records, triggers are re-fired on this subset of records.

That's fine, but when I modify some records in the first trigger attempt, and mark a few of them with addError(), then the second attempt gets the unchanged subset (without records marked with addError() but also without my modifications on the good ones).

Is there any way to preserve the state between all-or-none before insert attempts?


Storing only the good guys in a static collection do the trick. As each trigger attempt run in common transaction, static fields state are preserved, so it's easy to get the values from the previous iteration.

| improve this answer | |

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.