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
mahidhar Reddymahidhar Reddy 

trigger on account object,when we delete account record in account object same rcord will be saved in anothr custom object ....i need trigger code

Best Answer chosen by mahidhar Reddy
Rahul.MishraRahul.Mishra
Hi Mahidhar,

I have written trigger for you where I am taking the account name and creating another custom object for deleted account, you can use my code and update the fields accordingly:
trigger copyData on Account (Before delete) {

// Here I am using custom object , you use where you want to copy data
   List<Broker__c> lstBroker = new List<Broker__c>();
   
   for(Account acc : trigger.old) {
      Broker__c objBroker = new Broker__c();
      // I have only used name field for map, you can map what all field you want to map
      objBroker.Name = acc.Name;
      
      lstBroker.add(objBroker);
   }
    if(!lstBroker.isEmpty())
      insert lstBroker;
}

Mark my answer as best if it does help you.

Thanks,
Rahul

All Answers

Rahul.MishraRahul.Mishra
Hi Mahidhar,

I have written trigger for you where I am taking the account name and creating another custom object for deleted account, you can use my code and update the fields accordingly:
trigger copyData on Account (Before delete) {

// Here I am using custom object , you use where you want to copy data
   List<Broker__c> lstBroker = new List<Broker__c>();
   
   for(Account acc : trigger.old) {
      Broker__c objBroker = new Broker__c();
      // I have only used name field for map, you can map what all field you want to map
      objBroker.Name = acc.Name;
      
      lstBroker.add(objBroker);
   }
    if(!lstBroker.isEmpty())
      insert lstBroker;
}

Mark my answer as best if it does help you.

Thanks,
Rahul
This was selected as the best answer
mahidhar Reddymahidhar Reddy
tanq...rahul