Introduction to Salesforce Triggers Part -1
Introduction to Triggers:
Apex Trigger is an action which gets fired on the particular event. In salesforce trigger is apex code that executes before or after the below types of operations.
- Insert
- Update
- Delete
Undelete
Triggers will run before object records are inserted, updated, deleted into the database or after records are inserted, updated, deleted and restored.
- Apex Triggers can be classified 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, and to effect changes in other records.
- Events in triggers:
- Before Insert, Before Update, Before Delete
- After Insert, After Update, After
, After Undeletedelete
- When to use “before”
“after” triggers:vs
- Syntax to create
:sample trigger - Use below syntax to create
.trigger trigger ObjectName (<eveon s>){nt
// Code Goes Here :)
}
- Trigger Context Variables:
- All tri
gge rs define implicit variables that allow users to access run time context. These variables are contained in the ystem.trigger class.S - T
igger.Newr - T
igger.oldr - T
igger.NewMapr - T
r igg er. OldMap - T
r igg er.i sAfter - T
r igg er.is Before - T
r igg er.is Insert - T
r igg er.is Update - T
r igg er.is Delete - T
r igg er.isUn delete.
========================================================================
Category: Apex, Apex Trigger, Salesforce
0 comments