You need to sign in to do that
Don't have an account?

using apex triggers how to create a new contact record with values of account when the account is deleted
hi all...
actually when we delete an account, i need to create a new contact with the details of deleted account. how can we do this using apex triggers
actually when we delete an account, i need to create a new contact with the details of deleted account. how can we do this using apex triggers
Here is the sample code.
Best Regards,
Sameer Tyagi
www.mirketa.com
Sameer Tyagi
www.mirketa.com
I think you are trying to delete the Parent object Customer__c, and creating a record Child record Test__c,
and there is Master detail relationship in Customer__c and Test__c
During creation a record of Test__c, you need to set id of parent object.
con.Customer__c = // set id here
NOTE : you can not set the id of same Customer__c which you are deleting.
Sameer Tyagi
You can take reference from the below code, it will help you.
trigger CreateContact on Account (after delete) {
List<contact> contactList = new List<contact>();
for(account acc : trigger.old){
contact conObj = new contact();
conObj.lastname = acc.name ;
conObj.phone = acc.phone;
contactList.add(conObj);
}
if(!contactList.isEmpty()){
insert contactList;
}
}
If you find your Solution then mark this as the best answer.
Thank you!
Regards
Suraj Tripathi