Sudipta Deb

Sudipta Deb

Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect

Requirement:
Write a Trigger on Employee custom Object -> The requirement is that the trigger should prevent Delete operation on Employee custom Object if a particular field(i.e., canDelete__c) is not checked.
Solution:

trigger DeleteEmployeeTrigger on Employee__c (before delete) {
   if(Trigger.isDelete){
      for(Employee__c anEmployee : Trigger.old){
         if(!anEmployee.canDelete__c){
             anEmployee.addError(Cannot delete Employee:  + anEmployee.First_Name__c +   + anEmployee.Last_Name__c);
         }
      }
   }
}

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *