This Article is on Salesforce Trigger

before starting the Trigger Concept let's briefly discuss how the trigger will initiate and when. basically triggers and tightly coupled with Salesforce Objects (Object is nothing but Salesforce DataBase Table) and when we do some DML Operation (like insert, update, delete, upsert, undelete) on the Object then Salesforce trigger will execute. and The best practice is to maintain one Trigger per Object

let's jump into Trigger contexts, basically, trigger contexts are (2 - types) one is before, and after and the Trigger context is nothing but the state ( before Trigger context or after Trigger context ) where the Salesforce trigger running.

we have Trigger context variables to check where which state trigger is in like (Trigger.isBefore or Trigger.isAfter) and (Trigger.isExecuting, Trigger.isInsert, Trigger.isUpdate, Trigger.isUpsert, Trigger.isDelete) this all context variables will return the boolean if the trigger in that status and else it will return false

now lets start will playing with data before we start off doing it will need to know a few more context variables and here they are Trigger.new, Trigger.old, Trigger.newMap and Trigger.oldMap (These context variables help us give the data that we need to perform the DML Operation and runtime) and I will start explaining the one by one now.

Trigger context Trigger.new Trigger.old Trigger.newMap Trigger.oldMap

before Insert:- new (List), no, no, no

after Insert :- new (List), no, newMap(Map), no

before update :- new(List), old(List), newMap(Map), oldMap(Map)

after update:- new(List), old(List), newMap(Map), oldMap(Map)

before delete:- no, old(List), no, oldMap(Map)

after delete:- no, no, no, oldMap(Map)

after undelete:- new (List), no, newMap(Map), no

now let's jump into the combo of events and contexts

on before context - This will have access only to Trigger.new context variable and here we can only do pre-commit logic of data insert like field value changes and adding additional field values by querying the data, and then we can also perform the DML on other objects

on after context - This will have access to Map which contains the record id also in it and we can only do post-commit logic like sending an email triggering API calls and etc.


Salesforce Flows will do basic before commit logic

This is simply about Trigger

we will meet in the next article

~ Thank you ~


Salesforce Salesforce Developers

To view or add a comment, sign in

Others also viewed

Explore content categories