I'm throwing error before insert when there is duplicate email and performing some action, but when error is thrown all the operation i performed is rolled back. how to prevent rollback.

  • 2
    addError means that there is an error on record, and it can not be processed. I suggest you to use custom exception throwing, which can be catched
    – kurunve
    Aug 11, 2017 at 14:16

3 Answers 3


The rollback depends on how the DML was initiated.

  1. Insert, update, delete, etc is an all or none and rollback will occur

  2. Using database methods you can specify the behavior using the allOrNone option

    Database.insert(records, false);

Will allow records without error to be inserted and those with an error will not.

You can inspect the results using the SaveResult object.


for inserting bulk record use


It will not rollback all the records it will only add error to specific record.


Salesforce doesn't provide commit statement so you could save the data prior to that point and then throw the error.

When you throw any custom error or add an error to a record in Trigger, Salesforce will rollback the transaction. You you cannot change that behavior.

  • You can't save and then throw an error. It's not possible. And SF provides a means to alter the all or none behavior
    – Eric
    Aug 13, 2017 at 6:23

You must log in to answer this question.

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