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
Sushma PriyaSushma Priya 

Doubt on usage of before update and after update

Hi,

 

Can you please clarify the following doubts:

 

  1. When can before update and after update need to be used on an object.
  2. Please give some business scenarios for using before update and scenarios for using after update on an object.

 

Similarly, how can we decide on when to go for before insert and after insert. Also before delete and after delete.

 

Thanks,

Sush.

backupbackup

Sushma it is better to google for this information than posting in boards as Salesforce gives a very good explanation of before and after insert Triggers, also before and after delete.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers.htm

 

In terms of Business Logic,

Take a Company App for example, if you want to update the status of the employee after getting  confirmation, we use after insert because the operation has to take place after something has been changed in the record.

In case we want to update a record value with a default value like salary details etc from other object then we use before insert...

Before Delete is used if we want to update record details of this object ior related object before the record is deleted..After delete is used when we want to show the impact of deleting this record on another object....like deleting a child record can decrease the total count in parent record...suppose a company is parent and employees are its children...deleting an employee will decrease the count of employees in parent object...Also if we want to update the company object record before a child record is deleted then we use before delete operation...
This is more applicalble on business requirement...As you practice more, you will get working knowledge of each event with due time...
All the Best!