Triggers are the automated actions which are performed when ever DML operations are performed on the object.
Trigger are classified in to two types:
- Before triggers : These triggers are fired before the new data is saved to Sobjects (or) database.
- After triggers : These triggers are fired after the records are saved to Sobjects (or) database.
Trigger Events:
These are the events that will fire the trigger when DML is performed.
- Before insert
- Before update
- Before delete
- After insert
- After update
- After delete
- After undelete
Trigger context variables:
- These are variables/properties which are defined in trigger class.
- These variables will hold data required during the run-time of trigger.
Variables:
- Trigger.isinsert: (a)It is a Boolean value (b)It is set as true if trigger fired due to the DML operation of insert
- Trigger.isupdate: (a)It is a Boolean value ( b) It is set as true if the trigger fired due to the DML operation of update
- Trigger.isdelete: (a) It is a Boolean value ( b) It is set as true if the trigger fired due to the DML operation of delete
- Trigger.isundelete: (a) It is a Boolean value ( b) It is set as true if the trigger fired due to the DML operation of delete
- Trigger.isBefore: (a) It is a Boolean value (b) It is set as true if the trigger fired before saving the data to Sobject.
- Trigger.isAfter: (a) It is a Boolean value ( b) It is set as true if the trigger fired After saving the data to Sobject.
- Trigger.new: (a) It is list of Sobjects ( b) This will contain new version of records involved in DML statements.
- Trigger.old: (a) It is list of Sobjects ( b) This will contain old version of records involved in DML statements.
- Trigger.oldmap: (a) It is a map of records where id of the records store as key & records as value ( b) This will contains old version of records involved in DML operation
- Trigger.newmap: (a) It is a map of records where id of the records store as key & records as value (b) This will contains new version of records involved in DML operation
SYNTAX:
trigger TriggerName ON Sobject (event){
//implement logic here
}
No comments:
Post a Comment