+ Start a Discussion

Can someone help me figure out what this Apex Trigger means?

We had a developer write some code but noticed he left code for the same object in all sorts of places. Wondering if anyone can please let me know what this Apex Trigger is meant to do? 
trigger OpportunityStageTrigger on Opportunity (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
   OpportunityStageTriggerhandler handler = new OpportunityStageTriggerhandler(trigger.new, trigger.old, trigger.newMap, trigger.oldMap, trigger.isInsert,trigger.isUpdate, trigger.isDelete, trigger.isUndelete);

Foram Rana RForam Rana R
Hi Kjun,

What I Understood by review your Code is: There is one apex class name OpportunityStageTriggerhandler and we pass some context variable in its constructor and when we update the Opportunity then after we need to call AfterUpdateEvent() method in OpportunityStageTriggerhandler class.

If you have doubt in Context variable then please go through below link :

Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.

Thanks & Regards,
Foram Rana
Vershley JoyejobVershley Joyejob
Hello Kjun,

There's another class your should look for which is in the OpportunityStageTriggerhandler. This performs some operations whenever an opportunity record is updated.


- Vershley
Deepali KulshresthaDeepali Kulshrestha
Hi Kjun,

I've gone through your requirement and you can see what trigger do and how trigger work below:

A trigger is an Apex script that executes before or after specific data manipulation language (DML) events occur, such
as before object records are inserted into the database, or after records have been deleted. Triggers enable to perform custom
actions before or after changes to Salesforce records. A trigger is Apex code that executes before or after the following types of
operations like insert, update, delete and delete. There are two types of triggers:

1.Before triggers:
It is used to update or validate record values before saved to the database.

2.After triggers:
It is used to access values of the record that are stored in the database and use this value to make changes with other
record.After trigger records are read-only.

Trigger trigger Name on sObject(Trigger event)



3.Bulky Trigger:
All triggers are bulk triggers by default, and can process multiple records at a time. You should always plan on processing more
than one record at a time. Bulk triggers can handle both single record updates and bulk operations like:

-Data import
-com Bulk API calls
-Mass actions, such as record owner changes and deletes
-Recursive Apex methods and triggers that invoke bulk DML statements

A trigger is Apex code that executes before or after the following types of operations:


For Example, you can refer the below link:

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha