Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Make your voice heard. Take the 2019 Developer Survey now

A trigger is a feature of the Salesforce platform consisting of Apex code that executes before or after DML operations.

Apex can be invoked through the use of triggers. A trigger is Apex code that executes before or after the following types of operations:

  • insert
  • update
  • delete
  • undelete (after only)

For example, you can have a trigger run before an object's records are inserted into the database, after records have been deleted, or even after a record is restored from the Recycle Bin.

You can define triggers for any top-level standard object, such as a Contact or an Account, but not for standard child objects, such as a ContactRole.

  • For case comments, click Your Name | Setup | Customize | Cases | Case Comments | Triggers.
  • For email messages, click Your Name | Setup | Customize | Cases | Email Messages | Triggers.

Triggers can be divided into two types: - Before triggers can be used to update or validate record values before they are saved to the database. - After triggers can be used to access field values that are set by the database (such as a record's Id or lastUpdated field), and to affect changes in other records, such as logging into an audit table or firing asynchronous events with a queue.

Useful Documentation

history | excerpt history