Undelete Employee and Set Active Status

This trigger ensures that when an Employee record is undeleted, the “Active” field is automatically set to “True,” restoring the record’s operational status.

For more hands-on examples, check this YouTube playlist.

Solution:

trigger EmployeeTrigger on Employee__c (After undelete)
             { if(Trigger.isUnDelete){ if(Trigger.isAfter){
                                                                                EmployeeTriggerHandler.unDeletionofEmp(Trigger.New);
                           }
           }
}
public class EmployeeTriggerHandler{


     public static void unDeletionofEmp(List empList){
                    List<Employee_c> empListToBeUpdated = new
                    Lis<Employee_c>t(); for(Employee__c emp :
   empList){ Employee__c e = new Employee__c(); e.Id = emp.Id;
                  e.Active__c = true;
                  empListToBeUpdated.add(e);
}
 if(!empListToBeUpdated.isEmpty()){ update
               empListToBeUpdated;
         }
   }
}

Want to Apply As Content Writer?

Leave a Comment

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

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

Fill in this form and we will get in touch with you :)