Prerequisites:
- Tutorial #4: Creating and Instantiating Classes
- Tutorial #8: sObjects and the Database
Triggers are Apex code that execute before or after an insert, update, delete or undelete event occurs on an sObject. Think of them as classes with a particular syntax that lets you specify when they should run, depending on how a database record is modified.
The syntax that introduces a trigger definition is very different to that of a class or interface. A trigger always starts with the trigger keyword, followed by the name of the trigger, the database object to which the trigger should be attached to, and then the conditions under which it should fire, for example, before a new record of that database object is inserted. Triggers have the following syntax:
trigger triggerName on ObjectName (trigger_events) {
code_block
}
You can specify multiple trigger events in a comma-separated list if you want the trigger to execute before or after insert, update, delete, and undelete operations. The events you can specify are:
- before insert
- before update
- before delete
- after insert
- after update
- after delete
- after undelete
No comments:
Post a Comment