Trigger timing options
When you create or configure a trigger, you can optionally select when you want it to run during the lifecycle of a record. The interface only displays valid options for the type of trigger you are creating. Timing options that fire before a record is committed, such as a trigger to validate data, are different from those available for triggers that run after commit. In some cases, options show but are disabled. For example, in a new record trigger, all timing options are shown but Before Create and After Delete are disabled because they are not applicable when creating a new record.
Multiple triggers can have the same timing option. In this case, the order in which they run is determined by the order in which they appear in the object definition's Triggers table. The following table briefly describes each Timing Option:
Timing Option | When Run |
---|---|
Before Create | Before a record is created |
After Create | After a record is created (most commonly used timing) |
Before Update | Before a record is updated |
After Update | After a record is updated |
Before Delete | Before a record is deleted |
After Delete | After a record is deleted |
Before Restore | Before a record is restored from the Recycle Bin |
After Restore | After a record is restored from the Recycle Bin |
On Finalize | After input from grid controls, embedded quick create, and survey components (if present on the page) are processed. This option only applies when an individual record is created or updated through the user interface, and not through an API. |
On Login | When a user or portal user logs in |
On Logout | When a user or portal user logs out |
When a record is created, Platform:
- Creates a new record without committing it into the database.
- Runs all triggers with Before Create timing.
- Commits the new record to the database.
- Runs all triggers with After Create timing.
When a record is updated, Platform:
- Runs all triggers with Before Update timing (note that the record is not updated at this point of time).
- Commits the actual record update in the database.
- Runs all triggers with After Update timing. When a record is attached or detached using links in a related list component, the system runs After Update triggers on both sides of the relationship.
When a record is deleted, Platform:
- Runs all triggers with Before Delete timing.
- Moves the record to Recycle Bin.
- Runs all triggers with After Delete timing.
When a record is restored from the Recycle Bin, Platform:
- Runs all triggers with Before Restore timing.
- Moves the record from the Recycle Bin.
- Runs all triggers with After Restore timing.