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
Deepu2123Deepu2123 

Doing some research on Merge contacts

Hi Developers,
 
I am doing some research on Merge contacts. Please provide me some important points for merge considerations for standard and custom objects.
Points:
1. How can we merge more than three records
2. Share some points so i can add in reserch document which i need to send to the business.

Thanks....
Raj VakatiRaj Vakati
Please find my comments her e

1. How can we merge more than three records
Raj  : You cannt able to merge three records at a time ..First you need to merget two and take the result recrods and merget it 
 
// Insert new accounts
List<Account> ls = new List<Account>{
    new Account(name='Acme Inc.'),
        new Account(name='Acme') , 
		        new Account(name='Acme 2')
        };                                        
insert ls;

// Queries to get the inserted accounts 
Account masterAcct = [SELECT Id, Name FROM Account WHERE Name = 'Acme Inc.' LIMIT 1];
Account mergeAcct = [SELECT Id, Name FROM Account WHERE Name = 'Acme' LIMIT 1];
Account mergeAcct1 = [SELECT Id, Name FROM Account WHERE Name = 'Acme 2' LIMIT 1];

// Add a contact to the account to be merged
Contact c = new Contact(FirstName='Joe',LastName='Merged');
c.AccountId = mergeAcct.Id;
insert c;

try {
    merge masterAcct mergeAcct;
} catch (DmlException e) {
    // Process exception
    System.debug('An unexpected error has occurred: ' + e.getMessage()); 
}



2. Share some points so i can add in reserch document which i need to send to the business.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_merge.htm