How does the account merge mechanism consolidate duplicate enterprise accounts and associated child records?
Answer
Basics: Duplicates split activity history and opportunities across records. Merging picks a master, lets you choose the winning value for each conflicting field, and moves related contacts, opportunities, cases, notes, attachments and activities to the master.
How it works:
- Find duplicates (Duplicate Rules, matching rules, or reports).
- In Lightning, use Merge Accounts from the account list (select up to three) or the Duplicate Record Sets.
- Choose the master; select the field values to keep.
- Confirm; related records are re-parented, child accounts in the hierarchy move under the master, and losing accounts are deleted (recoverable from the Recycle Bin for 15 days).
- Duplicate rule alerts and merge jobs (where licensed) can help at scale.
Advanced / deep dive: Programmatic merge supports a master and up to two losers per statement. Triggers fire: delete triggers on the losers, update on the master, with MasterRecordId visible in before/after delete context, which integrations must handle to re-key external systems. Sharing: merged related records follow the master's sharing. Some situations restrict merging (for example Person Accounts only merge with Person Accounts; portal or partner users, and accounts with certain features, have limits; verify in current docs). Prevention is better: use matching rules and duplicate rules to block or alert at entry, and use Duplicate Jobs (edition-dependent) for cleanup. For massive cleanups, plan batches of merges and avoid sharing recalculation during business hours.
Code / config example:
Account master = [SELECT Id FROM Account WHERE :masterId];
List<Id> losers = <Id>{ dup1Id, dup2Id };
Database.MergeResult[] results = Database.merge(master, losers, );
(Database.MergeResult r : results) {
(!r.isSuccess()) { System.debug(r.getErrors()[].getMessage()); }
}