Sub topic 1
How Duplicate Management works
Duplicate Management is the set of Salesforce features that find records that probably describe the same real-world person or company, and then decide what happens next. This chapter gives the working model. Later chapters cover each piece in detail.
Prerequisites
This chapter assumes you can:
- Describe objects, fields and records, and tell Accounts, Contacts and Leads apart.
- Open Setup as an administrator and find a configuration page.
- Read a short Apex or SOQL snippet. Only the developer chapters later in the tutorial need this.
You do not need to have built a matching rule or duplicate rule before.
The two building blocks
Duplicate Management splits the work into two kinds of rules. Each has a different job.
- A matching rule decides whether two records are alike. It compares field values, such as name, email and phone, and produces a yes or no.
- A duplicate rule decides what happens when a matching rule says yes. It chooses an action when a user creates or edits a record, and it names the matching rule or rules to use.
A matching rule never stops a save and never warns anyone. A duplicate rule has no idea how to compare records. It only asks its matching rule and reacts to the answer. Keeping the two apart lets you reuse one matching rule in several duplicate rules, and change the user-facing behavior without touching the comparison logic.
| Aspect | Matching rule | Duplicate rule |
|---|---|---|
| Question it answers | Are these two records alike? | What do we do when they are? |
| Configured with | Field comparisons and match methods | Actions, conditions, and a matching rule |
| Visible to users | No, it runs behind the scenes | Yes, through alerts, blocks and reports |
| Works on | One object, or a pair of objects for cross-object matching | The object it is defined on |
What happens when a record is saved
When a user saves a record, or an integration does, Salesforce runs this sequence for each active duplicate rule on that object:
- Salesforce checks whether the duplicate rule's conditions apply to the record. A rule can be limited, for example, to certain record types or users.
- It runs the matching rule that the duplicate rule names, comparing the incoming record with existing records the user is allowed to see.
- If at least one existing record matches, the duplicate rule applies its action. If nothing matches, the save continues as normal.
The diagram leaves out the user-override step for alerts. An Allow rule with an alert shows the user the possible duplicates and lets them save anyway. A Block rule refuses the save.
What a rule can do
A duplicate rule applies its action separately for creating a record and for editing one. For each, you pick one of two main behaviors:
- Allow lets the save go through. You can add an alert, a report entry, or both.
- Block stops the save and shows a message you write. You can also record a report entry.
The alert is the message a user sees. The report entry is a row stored for later review, covered below. The next chapters explain how to choose among these and when to combine them.
How rules relate to each other
Matching rules and duplicate rules are separate setup items, and they depend on each other in a fixed order.
- A duplicate rule must point to at least one matching rule.
- A matching rule must be active before a duplicate rule that uses it can be activated.
- A single object can have several active duplicate rules, and each one runs on its own.
- A duplicate rule can use more than one matching rule. A record counts as a match if any of them finds a match.
Salesforce supplies standard matching rules and standard duplicate rules for Accounts, Contacts and Leads. They give you working behavior without any setup. Check whether they are active in your org before you assume they are protecting your data. If they are not enough, you build custom matching rules and your own duplicate rules.
Limits apply to how many rules can be active per object, and they vary by edition. Check the current Salesforce documentation before you plan a design with many rules.
Where duplicates are recorded
When a duplicate rule has a report action and finds matches, Salesforce records the match. It creates a duplicate record set that groups the records Salesforce considers duplicates of one another. Each record in a set is linked through a duplicate record item. Both are real records you can query and report on.
This is how you find duplicates that were allowed through, so you can review and merge them later. The following SOQL query lists the most recent sets:
SELECT Id, DuplicateRuleId, RecordCount
FROM DuplicateRecordSet
ORDER BY CreatedDate DESC
LIMIT 20If this query returns nothing, either no rule has a report action, or no duplicates have been found since the rule started running.
What Duplicate Management does not do
Knowing the limits prevents most early confusion.
- It does not clean existing data on its own. Duplicate rules run when records are created or edited. Records already in the org are not checked until someone edits them, or until you run a duplicate job, which is available only in some editions.
- It does not merge records for you. Rules find and flag duplicates. Merging is a separate manual step, covered in a later chapter.
- It only sees what the user can see. The comparison respects record-level security by default. A rule can miss a duplicate that the user has no access to. A later chapter shows how to change this.
- It is not a perfect judge. Fuzzy matching estimates likeness. Some true duplicates are missed, and some different records are flagged.
Common early mistakes
- Assuming a duplicate rule is enough on its own. Without an active matching rule it cannot be active.
- Testing with data that cannot match. If a test record differs from the existing one in every compared field, nothing is flagged, and it looks like the rule is broken.
- Forgetting the rule is for one object. A rule on Contacts does not warn about a duplicate Lead unless you set up cross-object matching.
- Blocking too early. A Block action on a new, untested matching rule can stop legitimate saves. Start with Allow plus alert and report, review the results, then tighten.
- Expecting a retroactive cleanup. A new rule does nothing about duplicates already saved.
How the rest of the tutorial builds on this
The chapters that follow take each box in the model one at a time. Next come matching rules: standard ones, exact versus fuzzy comparison, and custom rules with matching equations. After that come duplicate rules, their actions, scope and conditions, and cross-object matching. Then come duplicate record sets, merging, and the Apex and API behavior. The tutorial ends with testing and troubleshooting, and design practices.
Exercise
A user creates a Contact, and a possible duplicate exists, but the save goes through with no message. Name two separate things you would check, and say whether each belongs to the matching rule or the duplicate rule.
Show answer
First, check that the duplicate rule is active and that its action for creating records is Allow or Block with an alert. A rule set to Allow with only a report entry shows no message. That is a duplicate rule setting. Second, check that the matching rule compares fields in which the two Contacts actually share values, and that it is active. If the matching rule does not consider the records alike, the duplicate rule is never triggered. That is a matching rule setting. You could also check the duplicate rule's conditions and whether the user can see the existing Contact.
Exercise
Why can a Contact duplicate rule not be activated until its matching rule is active, and what does that tell you about the order of setup?
Show answer
The duplicate rule relies on the matching rule to decide whether records are alike, so it has nothing to ask until that rule is active. You set up and activate the matching rule first, then create or activate the duplicate rule that uses it.