Sub topic 12
Reviewing duplicate record sets and reports
This chapter assumes you know how a duplicate rule calls a matching rule, and that you have seen the action options (allow, block, alert, report). You should be comfortable with Setup, report builder, and basic SOQL. The Apex example is optional.
What a duplicate record set is
A duplicate record set is a group of records that a duplicate rule judged to be duplicates of one another. Salesforce stores each set as a DuplicateRecordSet record. Each member of the set is a DuplicateRecordItem record that points at the real Account, Contact, Lead, or other record.
Sets exist so that you can review duplicates after the fact. Alerts and blocks only help the person saving a record at that moment. A set gives an admin or data steward a persistent list to work through later.
The objects relate like this:
| Object | What one row represents | Key fields |
|---|---|---|
| `DuplicateRule` | A duplicate rule (the definition) | `DeveloperName`, `SobjectType` |
| `DuplicateRecordSet` | One group of matching records | `DuplicateRuleId`, `RecordCount` |
| `DuplicateRecordItem` | One record's membership in one set | `DuplicateRecordSetId`, `RecordId` |
When sets are created
A rule creates sets only when its action allows the save and its Report option is selected. Selecting Report is not enough on its own. These conditions all have to hold:
- The duplicate rule is active.
- The rule's action for the operation (create or edit) is Allow. The Report checkbox is available only with Allow, so a blocked save is never saved and creates no set.
- The saved record matches at least one other record under the rule's matching rule.
- The record is saved. A record that never reaches the database cannot be a set member.
Sets are created at save time. Records that were already duplicates before you activated the rule do not appear in any set until something saves them again, such as an edit, an import, or an API update. Many admins are surprised by empty reports right after activation for this reason.
Reviewing sets in the user interface
There are three places to look.
- Duplicate Record Sets tab. An admin can add this tab to an app. It lists sets and shows the rule that created each one. Opening a set shows its member records in a related list.
- Record pages. A record that belongs to a set can show its sets through the Duplicate Record Items related list. You can also put the Potential Duplicates component on a Lightning record page, so the person working a record sees likely duplicates in context.
- Reports. The Duplicate Record Sets and Duplicate Record Items report types are the best option for bulk review.
Building a useful report
Create a report from the Duplicate Record Items report type. Add the duplicate record set, the duplicate rule name, and the related record's key fields: name, owner, created date, and whichever fields you plan to compare during a merge. Group by Duplicate Record Set so that each cluster of matching records forms one visual block. Filter on created date to focus on recent activity, and on the rule name to review one rule at a time.
A good working report has these properties:
- It groups by set, so you read one cluster at a time.
- It shows the owner, so you can route cleanup to the right person.
- It includes created date, which helps you pick the surviving record when you merge.
- It filters to a single object. A cross-object rule can put Leads and Contacts in one set, so that report needs fields that exist on both.
Reports respect record sharing. A user sees an item only if they can see the underlying record, so a manager's report can show a different set size than an admin's. Check this first when two people report different numbers.
Querying sets with SOQL
Sets and items are ordinary objects, so you can query them. This lists the most recent sets and their sizes.
SELECT Id, DuplicateRuleId, RecordCount
FROM DuplicateRecordSet
ORDER BY CreatedDate DESC
LIMIT 20To see which records belong to one set, query the items. The Apex below defines the bind variable, so it runs as an anonymous Apex script.
List<DuplicateRecordSet> latest = [
SELECT Id, RecordCount
FROM DuplicateRecordSet
ORDER BY CreatedDate DESC
LIMIT 1
];
if (!latest.isEmpty()) {
Id duplicateSetId = latest[0].Id;
List<DuplicateRecordItem> items = [
SELECT Id, DuplicateRecordSetId, RecordId
FROM DuplicateRecordItem
WHERE DuplicateRecordSetId = :duplicateSetId
];
System.debug('Set ' + duplicateSetId + ' has ' + items.size() + ' items');
for (DuplicateRecordItem item : items) {
System.debug('Member record: ' + item.RecordId);
}
}RecordId is a polymorphic reference, which means it can point at different object types. Its prefix tells you the object. If you need field values from the member records, collect the IDs and run a second query against the specific object, such as Account or Contact.
Acting on what you find
Review is only useful if it ends in a decision for each set. A practical routine looks like this:
- Open a set and compare its members. Look at completeness, recency, and related data such as open opportunities, cases, and activities.
- Decide whether the records are true duplicates. Fuzzy matching produces false positives, such as two real people with the same name at one company.
- If they are true duplicates, merge them. The merging chapter covers survivor selection and field choices in detail.
- If they are not duplicates, leave the records alone. They will stay in the set until the data changes, and you can filter the report to reduce noise.
- If many false positives appear, tighten the matching rule rather than reviewing the same noise each week.
Sets keep in step with the data. When you merge or delete records, the set's membership changes, and a set that no longer holds at least two records has nothing left to review. Do not hand-edit DuplicateRecordSet or DuplicateRecordItem rows to "clear" a report. Fix the underlying records instead.
Common problems
| Symptom | Likely cause | What to check |
|---|---|---|
| No sets exist after activating a rule | Existing duplicates were never re-saved | Edit or reimport a sample record and see whether a set appears |
| Sets never appear for a rule | Action is Block, or Report is off | Open the rule and check the action and Report option for create and edit |
| Admin sees more items than a user | Sharing hides records from the user | Compare the two users' access to the records |
| Report shows only one record per set | Other members are hidden or were merged | Query `DuplicateRecordItem` as an admin |
| Sets keep growing with false matches | Matching rule is too loose | Review the matching equation and field conditions |
| Imported records are missing from sets | The rule does not run for that load path, or Report is off | Check the rule's operations and the load method |
Exercise
You activate a duplicate rule on Contacts with the action Allow and Report selected for create and edit. A week later, the Duplicate Record Sets report is empty, but you know thousands of duplicate contacts exist from an old import. Why, and what do you do?
Show answer
Sets are created only when a record is saved while the active rule runs. The old duplicates were saved before the rule existed, so no set was ever made for them. To get them into sets, save them again (for example with a data update or an edit) so the rule evaluates them, then rerun the report. Also confirm the rule is active and that the Report option is selected for the operation you use.
Exercise
A data steward and a sales manager run the same Duplicate Record Items report and see different counts of members in the same set. Name the most likely cause and how you would confirm it.
Show answer
Record sharing. Reports show only items whose underlying records the running user can see, so the manager sees fewer members. Confirm it by querying DuplicateRecordItem for that set as an admin (or running the report as an admin) and comparing the record IDs with what the manager can open.