How do Matching Rules and Duplicate Rules work together to prevent duplicate data entry?
Answer
Basics: Duplicates harm reporting and customer experience. Duplicate Management separates detection (matching rule) from action (duplicate rule), so the same matching logic can drive different behavior for different users.
How it works:
- Matching Rule: Setup > Duplicate Management > Matching Rules; pick object, define field comparisons (for example Account Name fuzzy AND Billing Street fuzzy), choose Exact or Fuzzy per field, and activate. Standard Account, Contact and Lead rules exist.
- Duplicate Rule: Setup > Duplicate Management > Duplicate Rules; choose object, record-level security (enforce or bypass sharing), actions for Create and Edit (Allow with alert/report, or Block), and attach one or more matching rules; set conditions (for example only when the user's profile is X).
- When a record is saved, Salesforce evaluates the matching rule against existing records and applies the duplicate rule action.
- Allowed duplicates are logged as Duplicate Record Items/Sets, available for reporting.
Advanced / deep dive: Fuzzy matching uses algorithms (for names, addresses, phone numbers) and covers common variants such as Bob/Robert; it is not available for every field type. Rules can compare across objects (for example Contact to Lead) via cross-object duplicate rules (Lead and Contact/Account). Sharing mode matters: "Enforce sharing rules" only compares against records the user can see, so hidden duplicates can still be created; "Bypass sharing rules" compares against everything. Through the API and Apex, a duplicate rule set to Allow does not block; with Block, the DML fails with DUPLICATES_DETECTED unless Database.DMLOptions.DuplicateRuleHeader.allowSave = true. Apex can proactively check with Datacloud.FindDuplicates.findDuplicates(records). Duplicate rules apply on record creation and edit, but do not retroactively clean existing data; use the Merge tools, Reports on duplicate sets, or a dedupe app. Only a small number of active rules per object are allowed; verify current limits.