---
schema_version: "1"
id: 492d52cdf288c42b194e2147ef4b52d968c7e1f3ca9347cba5795d197fc647b0
title: Trigger Exceptions
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_triggers_exceptions.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_exceptions.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8d15473b710ef15a8758c7fdcf83f07251399c00c9016743507ebfb221dbe1d8
---
# Trigger Exceptions

Triggers can be used to prevent DML operations from occurring by calling the addError() method on a record or field. When used on Trigger.new records in insert and update triggers, and on Trigger.old records in delete triggers, the custom error message is displayed in the application interface and logged.

![Note](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/images/icon_note.png)

#### Note

Users experience less of a delay in response time if errors are added to before triggers.

A subset of the records being processed can be marked with the addError() method:

- If the trigger was spawned by a DML statement in Apex, any one error results in the entire operation rolling back. However, the runtime engine still processes every record in the operation to compile a comprehensive list of errors.
- If the trigger was spawned by a bulk DML call in the Lightning Platform API, the runtime engine sets aside the bad records and attempts to do a partial save of the records that did not generate errors. See [Bulk DML Exception Handling](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_bulk_exceptions.htm).

If a trigger ever throws an unhandled exception, all records are marked with an error and no further processing takes place.

- [← Previous](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_knowledge_considerations.htm "Trigger Considerations for Knowledge Articles")
- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_bestpract.htm "Trigger and Bulk Request Best Practices")

#### See Also

- [_Apex Reference Guide_: SObject.addError()](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_methods_system_sobject.htm "Apex Reference Guide: SObject.addError() - HTML (New Window)")