I have an After event trigger on object A where in I have a condition checked in object A with addError and an update in object B.

During bulk dataload, when the condition in object A fails the adderror is thrown and the DML in object B is rolled back.

I have tried future calls as well. It did not work.

Can anyone help!

Thanks NB

  • 1
    Please paste your trigger code so that it helps other in helping you
    – Jarvis
    Feb 24 '16 at 7:57
  • In Short, in after event trigger, during bulk operation, if there is AddError() , then DML operation to other objects gets rolledback Feb 24 '16 at 7:59
  • @SFDCLearner is that code working for single operation?
    – kurunve
    Feb 24 '16 at 8:22
  • @SFDCLearner salesforce.stackexchange.com/questions/9502/…
    – kurunve
    Feb 24 '16 at 8:49
  • Yes it is working fine for single operation Feb 24 '16 at 9:22

We cannot prevent rollback when we use addError() on all rows in Apex.

However what we can do is perform partial processing using Database.insert(List objList, allORNone) or Database.Update((List objList, allORNone).

From the Docs:

The thing about partial processing is that even if individual records in the update cause exceptions, an exception won't be thrown. To deal with individual exceptions in this manner, we can do something like this:

Database.SaveResult[] lsr = Database.update(accounts, false); 

for(Database.SaveResult sr : lsr){ 
    if (!sr.isSuccess()) { 

Here we try to update a list of Accounts. The Database.update won't throw an exception, because we're allowing for partial processing. We then loop through the save result looking for errors. We can pass the save result to a method that will do some processing of the error records. And because we're doing partial processing, we won't stop the post-commit processing like the sending of emails.

One thing to realize about the partial processing method--automatic rollback of DMLs is disabled when you use it. If you switch from all or nothing to partial processing, you may need to change your code to handle your own rollback using Apex transaction control

  • How would you do that using the data loader, which is the one performing the DML? Feb 21 '17 at 20:21

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.