You need to sign in to do that
Don't have an account?
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 ??
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