Types:
Before Trigger: Executes Before save
After Trigger : Executes After save
Trigger Events:
*before insert
*before update
*before delete
*after insert
*after update
*after delete
*after undelete
Trigger.New: contains all the records that were inserted in insert or update triggers.
Holds only base fields and not related fields information
Trigger.Old: provides the old version of sObjects before they were updated in update triggers, or a list of deleted sObjects in delete triggers.
Before Trigger:The system saves the records that fired the before trigger after the trigger finishes execution. Hence No DML requrired
Trigger Context Variables
*isExecuting
*isInsert
*isUpdate
*isDelete
*isBefore
*isAfter
*isUndelete
*new
*newMap
*old
*oldMap
*operationType
*size
https://trailhead.salesforce.com/content/learn/modules/apex_triggers/apex_triggers_intro?trailmix_creator_id=shibua&trailmix_slug=ust-sfdc-dev-apex-vf-basics
Trigger Exceptions
addError(): For preventing records from being saved when certain conditions are met
Callouts:Apex calls to external Web services
Callout must be done asynchronously so that the trigger process doesn’t block you from working while waiting for the external service's response. The asynchronous callout is made in a background process, and the response is received when the external service returns it for eg, @future(callout=true)
HOw to Bulkify trigger
https://trailhead.salesforce.com/content/learn/modules/apex_triggers/apex_triggers_bulk?trailmix_creator_id=shibua&trailmix_slug=ust-sfdc-dev-apex-vf-basics
Top comments (0)