Apex Triggers are the "trigger points" of Salesforce. They execute custom actions before or after changes occur to your records—whether it's an insertion, update, or deletion.
"Every trigger is a bulk trigger by default."
They are capable of handling multiple records simultaneously. Always write your logic with Collection Patterns to ensure governance limit compliance.
Used primarily to **update additional values** on a record or **validate them** before they are committed to the database. These are the front-line guards of your data integrity.
Designed to update **related or unrelated records** and perform post-processing tasks once the initial record has been safely saved to the database.
trigger TriggerName on ObjectName (trigger_events) {
// Your custom code block goes here
}
Safety Protocol: Database changes are automatically rolled back if the trigger fails.
Available only for specific system objects. Invoked when records are recovered from the Recycle Bin.
Variables originate from the System.Trigger Class
"You cannot use DML operations on Trigger.new or Trigger.old variables."
Attempting an update or insert on these collections directly will result in a runtime exception.
"Trigger.old is always read-only. We can't make any changes on top of it."
Use this collection exclusively for comparing previous values to detect changes during an update.
"We can use Trigger.new in the before context to update values, but not in the after context."
Modifying fields in the Before context saves automatically without a DML call. In After, the records are already locked.
Initialization phase: Prime data before triggers fire.
Validation context: Perform pre-save updates and checks.
Compliance check: Execute standard and custom validation.
Data Guard: Final block before staging the save.
Database stage: Record is written but not committed.
Post-save logic: Coordinate related record updates.
Automation chain: Execute record-triggered after flows.
Finalization: Data is permanently saved to the cloud.
"Send Email, Async Jobs Like Future, Queueable, and Async paths in Record-Triggered Flows."