You need to sign in to do that
Don't have an account?
Nagarjun T
Trigger to copy account object field to custom object field before delete
Hi everyone,
before deleting the account iam trying to copy the account data to another custom object, how can i create the trigger can any one help this topic
before deleting the account iam trying to copy the account data to another custom object, how can i create the trigger can any one help this topic
trigger accountBackup_NaY on Account (before delete)
{
List<Backup_Data__c> lstToInsrt = new List<Backup_Data__c>();
for(Account deletedAcc : trigger.old)
{
Backup_Data__c obj = new Backup_Data__c();
obj.Name = deletedAcc.Name;
obj.Phone__c = deletedAcc.Phone;
obj.type__c = deletedAcc.Type;
obj.Account_Number__c = deletedAcc.accountnumber;
obj.fax__c = Decimal.valueOf(deletedAcc.Fax);
lstToInsrt.add(obj);
}
if(lstToInsrt.size()>0){
insert lstToInsrt;
}
}
All Answers
here is the sample trigger code. Thanks,
let us know if it is help you
This will be helps you try.
Please Let me Known it helpful or not and make it as best may be helps someone.
with
Like that makw how many columns you want
Error: Compile Error: Illegal assignment from String to Decimal at line 5 column 29
I have two objects one is 1.Standard Object-- Account
2.Custom Object -- Backup_Data__C
In Backup_Data__c object i created four fields Account name, phone, fax and type so now my question is if i deleted these fields contained record from account object,, before deleting that record i want to store that record in custom Backup_Data__C Object
Thanks
Only on fax field iam getting Error: Compile Error: Illegal assignment from String to Decimal at line 12 column 15
phone-- phone data type
fax -- Number(18, 0) data type
type -- picklist data type.
trigger accountBackup_NaY on Account (before delete)
{
List<Backup_Data__c> lstToInsrt = new List<Backup_Data__c>();
for(Account deletedAcc : trigger.old)
{
Backup_Data__c obj = new Backup_Data__c();
obj.Name = deletedAcc.Name;
obj.Phone__c = deletedAcc.Phone;
obj.type__c = deletedAcc.Type;
obj.Account_Number__c = deletedAcc.accountnumber;
obj.fax__c = deletedAcc.Fax;
lstToInsrt.add(obj);
}
if(lstToInsrt.size()>0){
insert lstToInsrt;
}
}
trigger accountBackup_NaY on Account (before delete)
{
List<Backup_Data__c> lstToInsrt = new List<Backup_Data__c>();
for(Account deletedAcc : trigger.old)
{
Backup_Data__c obj = new Backup_Data__c();
obj.Name = deletedAcc.Name;
obj.Phone__c = deletedAcc.Phone;
obj.type__c = deletedAcc.Type;
obj.Account_Number__c = deletedAcc.accountnumber;
obj.fax__c = Decimal.valueOf(deletedAcc.Fax);
lstToInsrt.add(obj);
}
if(lstToInsrt.size()>0){
insert lstToInsrt;
}
}
It is better to delete the fax field in Custom Object if we don't have any data still now in custom object and create new fax field with same data type of "fax field in Account". because may be we will face problems in future like, while matching the fax fields of both Objects etc.