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 Answer 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? Commented Oct 6, 2016 at 1:02
  • @HelloWorld your unit test would be responsible for calling the DML using allOrNone set to false.
    – sfdcfox
    Commented Oct 6, 2016 at 1:07

You must log in to answer this question.

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