Sub topic 12
Reviewing duplicate record sets and reports
This chapter assumes you can build a duplicate rule and choose its actions, as covered in the earlier chapters. For the Apex and SOQL parts, you also need basic Apex.
Where duplicate record sets come from
A duplicate record set is a group of records that a duplicate rule judged to be alike. A set exists only if the rule's action includes Report. Each set holds one or more duplicate record items. Each item points to one record in that group.
Salesforce stores these as two standard objects:
| Object | What one row represents |
|---|---|
| `DuplicateRecordSet` | One group of matching records, tied to the duplicate rule that found it |
| `DuplicateRecordItem` | One record's membership in one set |
Common reasons a set is missing
- The rule's Report option is off. Sets are not created retroactively for saves that already happened.
- The save was blocked. A blocked record is never saved, so it cannot become an item.
- The rule is inactive, or its conditions excluded the record.
- The users involved cannot see each other's records and the rule uses the sharing setting that respects record access.
Reviewing sets with reports
The usual route is a custom report type. Make Duplicate Record Sets the primary object and Duplicate Record Items the related object. Add the fields you need, such as the rule name, the record count, and the matched record's name. Group by duplicate set so each group reads as one cluster. From there, an admin or data steward can work through the list and merge records.
Querying sets with SOQL
You can also read the data directly. This query lists the latest sets and how many records each holds:
SELECT Id, DuplicateRuleId, RecordCount
FROM DuplicateRecordSet
ORDER BY CreatedDate DESC
LIMIT 20To see the records inside one set, query the items. Here the set Id is passed in from Apex:
public with sharing class DuplicateSetViewer {
public static List<DuplicateRecordItem> getItems(Id duplicateSetId) {
return [
SELECT Id, DuplicateRecordSetId, RecordId
FROM DuplicateRecordItem
WHERE DuplicateRecordSetId = :duplicateSetId
];
}
}RecordId is a polymorphic reference. It can point to an Account, Contact, or Lead, so check the Id prefix or use RecordId.getSObjectType() before you load the full record.
From review to cleanup
A set is a work list, not a fix. The records in it stay separate until you merge them, which the next chapter covers. After a merge, the losing records are removed, and the set no longer represents a live duplicate group.
Exercise
A duplicate rule with the action "Alert" and Report turned off has been active for a month. You query DuplicateRecordSet and find nothing. Why, and what must you change to start collecting sets?
Show answer
Sets are created only when the rule's Report option is enabled. Alert alone warns the user but stores nothing. Turn on Report for the rule. Only saves after that change will create sets, because past saves are not recorded retroactively.