# How do matching and duplicate rules protect data integrity in Sales Cloud databases?

**Topic:** Sales Cloud · **Difficulty:** Medium · **Tags:** Sales Cloud, Duplicate Management, Data Integrity

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-matching-and-duplicate-rules-protect-data-integrity-in-sales-cloud-databases

## Answer

**Basics:** Duplicate leads, contacts and accounts cause double outreach, bad reporting and merge work. Duplicate Management stops them at entry, rather than cleaning up later.

**How it works:** 1) Setup > Matching Rules: use a standard rule (Standard Account/Contact/Lead Rule) or create one with field comparisons (exact, fuzzy, with blank handling). Activate it. 2) Setup > Duplicate Rules: choose the object, select matching rule(s), set actions on Create and Edit (Allow or Block, Alert text, Report), and choose whether to enforce sharing rules or bypass them. 3) When a user saves, the rule runs after validation rules in the save order; matches show a banner or block the save. 4) Matches are logged in Duplicate Record Sets and Duplicate Record Items if Report is selected.

**Advanced / deep dive:** Fuzzy matching handles typos and nicknames, but some fuzzy methods consume more processing. Bypassing sharing lets a rep be warned about records they cannot see (useful, but leaks existence), while enforcing sharing misses hidden duplicates. Rules apply to API loads too: with an Allow-with-alert rule, API saves fail unless the caller passes the duplicate rule header; Apex uses `Database.DMLOptions.DuplicateRuleHeader.allowSave`. `Datacloud.FindDuplicates.findDuplicates(records)` lets Apex check without saving. Existing data is cleaned with Duplicate Jobs (higher editions only; verify edition) and merge. Per-object limits exist (commonly documented as five active duplicate rules and five active matching rules per object).

**Code / config example:**
```apex
Database.DMLOptions opts = new Database.DMLOptions();
opts.DuplicateRuleHeader.allowSave = true;   // save despite "Allow" alert rules
List<Database.SaveResult> res = Database.insert(newLeads, opts);
for (Database.SaveResult r : res) {
    if (!r.isSuccess()) {
        for (Database.Error e : r.getErrors()) {
            if (e instanceof Database.DuplicateError) { /* inspect matches */ }
        }
    }
}
```

**Hidden gotchas & must-remember points:**
- Duplicate rules are not active until both the matching rule and duplicate rule are activated.
- Block rules cannot be skipped by users; the API header only bypasses Allow rules.
- Matching is not retroactive; run a Duplicate Job for existing data.
- Rules run after validation rules but before the record is saved.
- Fuzzy rules on large data affect matching time; keep keys selective.
- Lead conversion triggers rules on the created account and contact.

**Best practice:** Start with Allow plus Report to measure matches, then move high-confidence rules to Block.

---
Source: ForceChallenges · last updated 2026-11-02
