Development questions

What happens if an unhandled exception occurs inside a trigger during a bulk DML operation (insert list vs Database.insert(list, false))?

  • insert list; (all-or-none): if any record fails or an uncaught exception occurs, the whole DML rolls back and a DmlException is thrown.
  • Database.insert(list, false): partial success is allowed. Records failing validation or addError() are reported in SaveResults, others commit.

Important: an unhandled exception thrown inside trigger code (like a NullPointerException) is not a per-record failure; it fails the whole chunk and rolls it back, even with allOrNone=false. Use addError for record-level failures and try/catch for expected exceptions.

apex-triggertriggerdmlexception-handling