+ Start a Discussion
force noviceforce novice 


When we will use before & after triggers?
Best Answer chosen by force novice
Before triggers are used when you want to change values of fields in the object that the trigger fires for.  This is because in a before trigger, the record is not yet committed to the database.  You can change fields in the record without having to do any DML.  The new values will go into the database when the before trigger completes and the record is committed.

Note that in a "before insert" trigger, records don't have IDs yet.

After triggers are used when you want to modify (or create) related objects.

Beware of updating the trigger records in an after trigger - particularly "after update".  Updating a record in its "after update" trigger will cause the "after update" trigger to be called recursively.

Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Blog: GlynATheApexGuy@blogspot.com
Twitter: @GlynAtClosedWon