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 aDmlExceptionis thrown.Database.insert(list, false): partial success is allowed. Records failing validation oraddError()are reported inSaveResults, 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
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?