Sub topic 4
Exact versus fuzzy matching
This chapter assumes you can open Setup as an administrator, know what a matching rule and a duplicate rule are, and have seen the standard Account, Contact and Lead objects. Developers can follow the Apex example at the end, but nothing else here requires code.
Every field comparison in a matching rule uses a match method. The two methods are exact and fuzzy. Your choice of method decides which duplicates you catch, which you miss, and how many false alarms users see.
What exact matching does
Exact matching compares two field values and reports a match only when they are the same. Salesforce ignores letter case, so ACME and acme match. Everything else must be identical, including spaces, punctuation and spelling.
| Value on the existing record | Value on the new record | Exact match? |
|---|---|---|
| `[email protected]` | `[email protected]` | Yes |
| `[email protected]` | `[email protected]` | No |
| `Acme Corporation` | `Acme Corp` | No |
| `John` | `Jon` | No |
Exact matching is predictable. If a rule fires, you can explain why by comparing the two values. It also has the fewest false positives. The cost is that small typing differences defeat it, so it misses duplicates that a person would spot immediately.
Exact matching suits fields that are meant to be unique or canonical:
- Email addresses
- External IDs and other custom identifiers
- Account numbers
- Postal codes, when your data entry is consistent
What fuzzy matching does
Fuzzy matching treats values as the same when they are close enough. Salesforce uses algorithms built for the type of data in the field, not one generic string comparison. For a name field, the algorithm accounts for several kinds of variation:
- Nicknames, such as
BobandRobert - Phonetic spelling, such as
JonandJohn - Initials, such as
J.forJohn - Small spelling differences, such as
SmithandSmyth
For company names, the algorithm also copes with common suffixes and abbreviations, so Acme Corporation and Acme Corp can be treated as a match. Street and city fields get similar tolerance for abbreviations like St and Street.
Fuzzy matching catches the duplicates that real data entry produces: a sales rep types Jon, a web form captured John, and an import file had Johnny. The cost is that you can no longer explain a match by comparing strings character by character, and you will see some false positives.
Which fields support fuzzy matching
You do not pick a method freely for every field. The options depend on the field, and the choice appears when you add the field to the matching equation.
- Exact matching is available on all fields that matching rules support.
- Fuzzy matching is offered only for certain standard fields, such as first name, last name, company name, title, street and city. Each offers a fuzzy method designed for that field.
- Custom fields can be matched exactly, but not fuzzily.
Check the picker in your org instead of relying on a memorized list. The method names show the field they apply to, for example "Fuzzy: First Name" versus "Fuzzy: Company Name". The set of fuzzy options can change between releases.
Combining methods in one rule
A matching rule usually mixes methods in its equation. A typical pattern uses fuzzy matching on the human-entered fields and exact matching on a stable identifier:
- (Fuzzy First Name AND Fuzzy Last Name AND Exact Email)
- OR (Fuzzy First Name AND Fuzzy Last Name AND Fuzzy Company Name)
Fuzzy fields make the rule tolerant of typos. The exact field keeps it from matching two different people who share a common name. The standard Contact rule is built on this idea, which is why it is often enough before you need a custom rule.
Here is how a comparison moves through a rule:
Choosing a method
Use these criteria to decide for each field:
- Is the value a identifier or free text? Identifiers such as email or an external ID point to exact. Names and addresses point to fuzzy.
- How clean is the data? Data from controlled sources, such as system integrations, can use exact matching. Data typed by people or imported from spreadsheets needs fuzzy matching.
- What does a false positive cost? If you block saves, a wrong match stops a user from working, so favor exact matching or add an exact condition. If you only alert or report, you can accept fuzzy matches and let people judge.
- What does a missed duplicate cost? A missed duplicate lets bad data into your org, which is later work for a merge. If that is expensive, accept more fuzziness.
Common errors
- Expecting fuzzy matching on a custom field. The field only offers exact. If you need approximate matching on custom data, copy the value into a supported standard field, or accept exact matching on a normalized value.
- Using exact matching on a phone number or name and wondering why obvious duplicates slip through.
(312) 555-0100and312-555-0100differ as strings. Check whether a fuzzy option exists for the field, or normalize the data on entry. - Blocking on fuzzy matches alone. A fuzzy-only equation on first and last name will match two real people called
Jon SmithandJohn Smyth. Pair fuzzy fields with an exact field before you block. - Forgetting blank fields. Two records with a blank email do not match on that field by default. Each field has a setting for whether blanks count, covered in the chapter on matching equations. This often explains a duplicate that was not flagged.
- Treating fuzzy results as a guarantee. Fuzzy matching reduces misses but does not remove them. Heavily abbreviated or misspelled values can still fall outside the match threshold.
Seeing the difference from Apex
You can test how your active rules treat a record without saving it. Datacloud.FindDuplicates.findDuplicates runs the active duplicate rules against an unsaved record. If your Contact rule uses fuzzy first name, a candidate with Jon can find a saved John Smith.
Contact candidate = new Contact(
FirstName = 'Jon',
LastName = 'Smith',
Email = '[email protected]'
);
List<Datacloud.FindDuplicatesResult> results =
Datacloud.FindDuplicates.findDuplicates(new List<Contact>{ candidate });
for (Datacloud.FindDuplicatesResult findResult : results) {
for (Datacloud.DuplicateResult dupResult : findResult.getDuplicateResults()) {
for (Datacloud.MatchResult matchResult : dupResult.getMatchResults()) {
for (Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()) {
System.debug('Possible duplicate: ' + matchRecord.getRecord());
}
}
}
}What this prints depends on the active rules and the data in your org. If you change the first-name field in your matching rule from fuzzy to exact and run it again, a saved John should stop appearing, which shows the difference directly.
Summary of the trade-off
| Row | Exact | Fuzzy |
|---|---|---|
| Matches | Identical values, ignoring case | Similar values |
| False positives | Rare | More likely |
| Missed duplicates | More likely | Less likely |
| Explainable | Easy | Harder |
| Field support | All supported fields | Selected standard fields |
| Best for | Identifiers, controlled data | Names, companies, addresses |
Exercise
Your org captures leads from a web form and from trade-show spreadsheets. Reps report the same people entered twice, once as "Robert Lee" and once as "Bob Lee", always with the same email address. You want to block the second save. Which match methods would you use for first name, last name and email, and why?
Show answer
Use fuzzy matching on first name, since nickname handling lets "Bob" match "Robert". Use fuzzy or exact matching on last name. Use exact matching on email. Because the action is Block, the exact email condition limits false positives: a block should happen only when the email is identical and the names are close. A name-only fuzzy equation would risk blocking two different people, so the email condition should be required.