function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Soubhagya Ranjan 2Soubhagya Ranjan 2 

merge account

Hi ,

my requirement is to merge account records with same name . after merge i will store the deleted record value in another object  . the deleted record which will store in new object will have the id of the master record of account to which it is merged . 
Saurabh BSaurabh B
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;

Please mark this as Best Answer if it helps you!
Soubhagya Ranjan 2Soubhagya Ranjan 2
Hi thanks for reply .. but I want the master record id in a new filed in the cuatom object for all the deleted records . Suppose ACC1 ACC2 ACC3 are there if we merge all to ACC1 then in new cuatom object I want acc2 and ACC3 with the id of ACC1 in a new field