Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
Diagram illustrating the process and data implications of Salesforce lead merging operations on records.
Admin

Salesforce Lead Merging: What Happens to Your Data?

Merging leads seems simple until you realize it triggers deletes and updates that can break your automation. This post breaks down exactly what happens to your fields and related lists when you hit that merge button.

The short answer

Salesforce lead merging combines up to three lead records into a single master record by executing an update on the master and deleting the duplicates. The operation automatically reparents related items like tasks and campaign history while executing standard update and delete trigger logic.

Key takeaways Verify that master records satisfy all active validation rules before initiating a merge to prevent the entire operation from failing. Account for trigger execution during merges, as the master record fires before and after update triggers while duplicate records fire before and after delete triggers. Explicitly assign field values from duplicate records to the master record in Apex prior to merging, because Database.merge() defaults to retaining the master record's values. Check the returned Database.MergeResult object when running merges programmatically to confirm success and catch validation or trigger errors. Ensure users have the Delete permission on Leads, which is required to complete a merge.

If you've spent more than five minutes looking at a marketing-heavy org, you know that Salesforce lead merging is a daily necessity. We've all seen those duplicate records piling up from web-to-lead forms or messy imports. It's one of those tasks that seems simple on the surface, but if you don't know what's happening under the hood, you can end up with missing data or broken automation.

What actually happens during Salesforce lead merging?

At its core, merging is just a fancy way of cleaning house. You're taking up to three Lead records and squashing them into one "master" record. But it isn't just a simple copy-paste job. Salesforce actually performs a delete operation on the duplicate records and an update operation on the master. So, if you've got triggers or flows running on those events, they're going to fire.

When you use the standard UI, you get to pick which record stays and which field values are the "winners." Once you hit that merge button, the losing records are sent straight to the Recycle Bin. They'll sit there for 15 days, just in case you realize you made a massive mistake and need to bring them back. But keep in mind, restoring a lead doesn't always perfectly undo the merge logic for related items.

One thing that trips people up is how fields are handled. In the UI, you're the boss. You pick the email from record A and the phone number from record B. But if you're doing this via the API or Apex, the master record's values are what stick unless you've written specific code to pull data from the duplicates first. It's a classic "gotcha" for developers who expect Salesforce to magically pick the most recent data.

A technical diagram showing the merging of duplicate Salesforce lead records into a single master record, including the automatic re-parenting of tasks and events.

A technical diagram showing the merging of duplicate Salesforce lead records into a single master record, including the automatic re-parenting of tasks and events.

Now, what about the "child" records? This is the best part of Salesforce lead merging. Most related items - like your tasks, events, and campaign history - get re-parented to the master record automatically. Your sales team won't lose the history of their calls or emails just because you cleaned up a duplicate. Even custom objects with a lookup to the Lead will usually follow the master, provided there aren't weird sharing constraints or required field issues in the way.

If you're dealing with massive amounts of duplicates, you might want to check out my guide on managing Salesforce large data volumes to keep things snappy. Merging thousands of records at once can hit limits faster than you'd think.

Technical gotchas with Salesforce lead merging

Here is where it gets interesting for the admins and devs. Because a merge is technically an update and a delete, your automation is going to go nuts if you aren't prepared. The master record will fire "before update" and "after update" triggers. The losing records will fire "before delete" and "after delete" triggers.

I've seen teams accidentally trigger a whole chain of welcome emails because the master record update met some criteria they forgot about. Deciding whether to handle your cleanup logic in a trigger or a flow? I've written about Apex vs Flow which covers exactly when to use each for this kind of scenario.

Pro tip: Always check your validation rules before a big merge project. If the master record fails a validation rule during the update phase of the merge, the whole thing will fail. There is nothing more frustrating than trying to merge 50 leads and having half of them bounce because of a "Required Field" rule that wasn't there when the lead was created.

Using Database.merge() in Apex

If you're automating this, you'll be using the Database.merge() method. It's pretty straightforward, but you have to be intentional. You pass in the master record and a list of the IDs you want to kill off. Here's a quick look at how that looks in the real world:

Lead masterLead = [SELECT Id, Company FROM Lead WHERE Id = :masterId];
Lead duplicateLead = [SELECT Id FROM Lead WHERE Id = :dupId];

// You can manually sync fields here before the merge
masterLead.Company = 'The Correct Company Name';

Database.MergeResult result = Database.merge(masterLead, duplicateLead);

The MergeResult is your friend here. It'll tell you if the merge actually worked or if a trigger or validation rule blocked it. Don't just assume it worked - always check those results in your logs.

Key Takeaways for Salesforce lead merging

  • Master vs. Loser: The master record is updated; the others are deleted and moved to the Recycle Bin.
  • Automation: Both update and delete triggers will fire. Be ready for that.
  • Reparenting: Activities and Campaign Members move to the master record automatically.
  • Permissions: You need the "Delete" permission on Leads to perform a merge. No delete permission, no merge.
  • UI Limit: You can only merge 3 records at a time through the standard Salesforce interface.

Look, Salesforce lead merging isn't the most glamorous part of being a consultant, but getting it right saves you a massive headache later. My advice? Test your merge logic in a sandbox first. See how your flows react. Check if your third-party integrations (like Marketo or HubSpot) freak out when a record they're tracking suddenly disappears into the Recycle Bin. A little testing now prevents a lot of data cleanup later.

Frequently asked questions

What happens to related records and duplicate data during a Salesforce lead merge?

The master lead record is updated, and the duplicate records are deleted and moved to the Recycle Bin for 15 days. Related child records, including tasks, events, and campaign history, are automatically reparented to the master record.

Which triggers fire during a lead merge in Salesforce?

The master record fires before update and after update triggers. The losing duplicate records fire before delete and after delete triggers.

How do you merge leads using Database.merge() in Apex?

Pass the master Lead record and the duplicate Lead record or ID list into Database.merge(). Because the master record's field values are retained by default in Apex, any desired field updates from duplicate records must be explicitly set on the master before calling the method.

How many leads can you merge at once in Salesforce?

You can merge up to three lead records at a time when using the standard Salesforce user interface.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment