Search
  • Tapeshwar Kumar

Apex Triggers

Updated: Nov 29, 2018

Perform actions before or after the events like insert/update /delete and After Undelete.



  • Before Triggers:- Validate the record’s value before it is going to save to the database.

  • After Triggers:- Get System generated values after saved the record to the database. like (Id,CreatedBy,LastModifiedDate etc).


Trigger Events

  1. Before Insert

  2. After Insert

  3. Before Update

  4. After Update

  5. Before Delete

  6. After Delete

  7. After Undelete


Context Variables

  1. isBefore

  2. isAfter

  3. isInsert

  4. isUpdate

  5. isDelete

  6. isUndelete

  7. isExecuting

  8. size

  9. new

  10. newMap

  11. old

  12. oldMap

Context Variable Consideration

Trigger Structure

trigger ContactTrigger on Contact (before insert, before update, before delete, after insert, after update, after delete, after undelete) {

     if(Trigger.isBefore){
        if(Trigger.isInsert){
    
        }else if(Trigger.isUpdate){
    
        }else{
        
        } 
     }else{
        if(Trigger.isInsert){
   
        }else if(Trigger.isUpdate){
   
        }else if(Trigger.isDelete){
    
        }else{
     
        }
     }
}




84 views