1

Can someone explain to me in very simple how the AllorNone works in a before insert trigger?

I was under the assumption that AllorNone is default false. I have a before insert trigger that checks for duplicates and uses addError() to prevent save. Test class fails in this scenario, insert 1 record -> insert list with one good, one duplicate.

Is AllorNone not default false in a trigger? If not, any ideas on allowing partial save in a before insert trigger?

1

AllOrNone is set by the caller, not the trigger itself. When you use DmlOptions, the default is false. When you use the single parameter database methods or the inline DML statements, the default is true.

So, to allow partial success in Apex Code, you normally do this:

Database.insert(records, false);
  • Since I'm doing the dupe check before insert, how do I get around it? – Hello World Oct 6 '16 at 1:02
  • @HelloWorld your unit test would be responsible for calling the DML using allOrNone set to false. – sfdcfox Oct 6 '16 at 1:07

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.