You need to sign in to do that
Don't have an account?
PRADEEP YADAV 5
Save the previous details of the opportunity records to BackUp record whenever any changes are being made to any opportunity record
trigger OpportunityBackup on Opportunity (after update)
{
List<My_Backup__c> lstToInsrt = new List<My_Backup__c>();
for(Opportunity op1 : Trigger.new)
{
if(trigger.oldMap.get(op1.Id).Name !=op1.Name)
{
My_Backup__c backup = new My_Backup__c();
backup.Name = trigger.oldMap.get(op1.AccountId).Name;
lstToInsrt.add(backup);
}
}
if(lstToInsrt.size()>0)
{
update lstToInsrt;
}
}
{
List<My_Backup__c> lstToInsrt = new List<My_Backup__c>();
for(Opportunity op1 : Trigger.new)
{
if(trigger.oldMap.get(op1.Id).Name !=op1.Name)
{
My_Backup__c backup = new My_Backup__c();
backup.Name = trigger.oldMap.get(op1.AccountId).Name;
lstToInsrt.add(backup);
}
}
if(lstToInsrt.size()>0)
{
update lstToInsrt;
}
}
Error
Try the below code:
Thanks,
Maharajan.C