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;
}
}
}