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
subbu123.pbt@gmail.comsubbu123.pbt@gmail.com 

before insert and before update

what is the best real time scnerio for before insert  and before update  for interview purpose ?

 

can u say ?

 

thank u .

vasuroyvasuroy

if we want to assign a field to a specific value   in a record before we write the data to the database we can use before insert

in a trigger , 

if we wanto to update the field a specific value before updating the record we can user before update in the trigger

Team WorksTeam Works

Thumb rule :

Before triggers are used if you are performing the update/insert on the object you are writing the trigger(in this case you do not need to use the update/insert keywords explicitly). If you are doing the update/insert on a related object use after trigger.

 

Also if you need to say validate the data or do some data checks use before triggers nad for operations eg send an email you can use after triggers.

 

Mark this as solution if helps and hit kudos

 

Cheers!

 

Yoganand GadekarYoganand Gadekar

Before insert: fires trigger before the record is inserted (for the first time, fires only once for one record)

before update: fires trigger before record is updated(every time the record is updated, the trigger will fire)