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

Hi, I need help to create a handler class for following trigger
trigger AccountMergeTrigger on Account (after delete) {
List<Account_Merge_History__c> listAccountBackup = new List<Account_Merge_History__c>();
for(Account acct : trigger.Old) {
if(String.isNotBlank(acct.MasterRecordId)) {
listAccountBackup.add(new Account_Merge_History__c(Name = acct.Name,ma_a__c =acct.MasterRecordId, ma_b__c = acct.Id, ma_e__c = acct.Id, ma_f__c = acct.MasterRecordId ));
}
}
if(listAccountBackup.size() > 0) {
insert listAccountBackup;
}
}
Please suggest
List<Account_Merge_History__c> listAccountBackup = new List<Account_Merge_History__c>();
for(Account acct : trigger.Old) {
if(String.isNotBlank(acct.MasterRecordId)) {
listAccountBackup.add(new Account_Merge_History__c(Name = acct.Name,ma_a__c =acct.MasterRecordId, ma_b__c = acct.Id, ma_e__c = acct.Id, ma_f__c = acct.MasterRecordId ));
}
}
if(listAccountBackup.size() > 0) {
insert listAccountBackup;
}
}
Please suggest
use below code :
trigger : apex class i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
All Answers
Hi Rohan,
Please follow the below code. It will help and guide you to create helper class.
trigger AccountMergeTrigger on Account (after delete) {
AccountHandler.checkNotBlank(Trigger.Old);
}
create New Class
Public static class AccountHandler{
public static void checkNotBlank(Account trgOldLst){
List<Account_Merge_History__c> listAccountBackup = new List<Account_Merge_History__c>();
for(Account acct : trgOldLst) {
if(String.isNotBlank(acct.MasterRecordId)) {
listAccountBackup.add(new Account_Merge_History__c(Name = acct.Name,ma_a__c =acct.MasterRecordId, ma_b__c = acct.Id, ma_e__c = acct.Id, ma_f__c = acct.MasterRecordId ));
}
}
if(listAccountBackup.size() > 0) {
insert listAccountBackup;
}
}
}
Thanks
use below code :
trigger : apex class i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com