function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
force noviceforce novice 

Triggers

When we will use before & after triggers?
Best Answer chosen by force novice
GlynAGlynA
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