Merge trigger example in Salesforce

When merge event occurs, in the deleted records, MasterRecordId field will be populated with the winning record id. The winning record will be updated with the values selected.

In the below trigger, when accounts are merged, then deleted record's Name and Website will be stored in Account Backup custom object.

Sample Trigger:

trigger AccountMergeTrigger on Account (after delete) {
    List<Account_Backup__c> listAccountBackup = new List<Account_Backup__c>();
    for(Account acct : trigger.old) {
        if(String.isNotBlank(acct.MasterRecordId)) { 
            listAccountBackup.add(new Account_Backup__c(Name = acct.Name, Website__c = acct.Website));  
    if(listAccountBackup.size() > 0) {
        insert listAccountBackup;


1 comment:

  1. we do have a case (Case A)created with subject line : checking for the duplicates .Now when other user or the same user creates another case (Case B) with the same subject line ,then the system should automatically identify it as a duplicate case and close the case (Case B) by adding the case comments to the existing case [case A] .