function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
devendra dhakadevendra dhaka 

Undeletion of custom records

trigger DeleteAllLeaveBalanceRecordForThisLeaveType on LeaveType__c (before delete) {
 
  set<id> ltList = Trigger.oldMap.keyset();
     
   if(trigger.isDelete)
   {
      
     
      List<Leave_Balance__c> LBList = [SELECT id FROM Leave_Balance__c WHERE LeaveType__c IN : ltList ];
      delete LBList;  
     
   }
 
}

 

 

This is my code for delete leave balance rows. If I undelete the leave_type record , how can i undelete the leave balance records??

 

 

 

if(trigger.isunDelete)
   {
      
     
      List<Leave_Balance__c> LBList = [SELECT id FROM Leave_Balance__c WHERE LeaveType__c IN : ltList ];
      undelete LBList;  
     
   }

 

Will this code work if I attach it to the trigger ??

yvk431yvk431

first of all you need add the trigger event  after undelete along with before delete. Also while querying for the the deleted records we should include the following  Where isdeleted = true ALL ROWS. 

 

One more thing is that you should used Trigger.NewMap instead of Old Map for unDelete event

 

 

--yvk