0

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.

1
  • 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 '17 at 14:16
1

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.

0

for inserting bulk record use

database.Insert

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

-1

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.

1
  • 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 '17 at 6:23

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.