Triggers in Salesforce

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
• merge
• upsert
• undelete

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.

Cheers!!!

No comments:

Post a Comment