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
Prashant Pandey.Prashant Pandey. 

Write a trigger - Table Student , Table Student_backup - When we delete any record in Table Student , It should be stored in Student_backup Table.

ANUTEJANUTEJ (Salesforce Developers) 
Hi Prashant

You can try checking the below trigger snippet code and modify it as per your use case.
 
trigger createBackup on Account (after delete) 
{
 if(trigger.isDelete && trigger.isAfter)
 {
  List<My_Backup__c> lstToInsrt = new List<My_Backup__c>();  
  for(Account deletedAcc : trigger.old)
  {
   system.debug('deletedAcc '+deletedAcc );
   My_Backup__c backup = new My_Backup__c();
   backup.Name = deletedAcc.name;
   lstToInsrt.add(backup);
   system.debug('backup '+backup);
  }
  if(lstToInsrt.size()>0)
  {
   insert lstToInsrt;
   system.debug('list'+lstToInsrt);
  }
 }
}

Please do note this is a sample code and you need to modify it as per your use scenario and names in the org.

>> reference: https://developer.salesforce.com/forums/?id=906F0000000MGYgIAO

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Malika Pathak 9Malika Pathak 9
Hi Prashant,
please find the solution below
 
trigger tableStudentTrigger on Table_Student__c (After Delete) {
    if(Trigger.isAfter && Trigger.isDelete){
        tablestudentTriggerhandler.studentBackup(trigger.old);
    }
}
public class tablestudentTriggerhandler {
    public static void studentBackup(List<Table_Student__c> studentList){
        try{
            List<Table_Student_backup__c> backupList=new List<Table_Student_backup__c>();
        for(Table_Student__c studentObj:studentList){
            Table_Student_backup__c backupObj=new Table_Student_backup__c();
            backupObj.Name=studentObj.Name;
            backupList.add(backupObj);
        }
        if(!backupList.isEmpty()){
            insert backupList;
        }
        system.debug('studentList==>'+backupList);
        }catch(Exception e){
            system.debug('error is =>'+e.getMessage()+' at line =>'+e.getLineNumber());
        }
        
    }

}
If you find this solution is helpful for you please mark best answer.
Andy NillsonAndy Nillson
This is great solution, Malika