Sub topic 6
Matching equations, field conditions and blank fields
This chapter assumes you can navigate Setup as an administrator. It also assumes you know that a matching rule decides whether two records are alike, and that a duplicate rule decides what happens next. You should already know the difference between exact and fuzzy matching. Here you will see how a custom matching rule combines several field comparisons into one verdict, and how blank fields change that verdict.
Field conditions: the building blocks
A custom matching rule is a list of field conditions. Each condition names one field and one matching method, such as Exact or a fuzzy variant for that field. Salesforce compares the incoming record with an existing record and gives each condition a result of match or no match.
Each condition also has a Match Blanks checkbox. It decides what happens when the field is empty on both records.
| Match Blanks setting | Both records blank in this field | One blank, one filled |
|---|---|---|
| Unchecked (default) | No match | No match |
| Checked | Match | No match |
A blank value on only one side never matches. The checkbox only affects the case where both sides are blank.
The matching equation
The matching equation combines the condition results into one decision. Each condition gets a number in the order you list it. The equation joins those numbers with AND, OR and parentheses.
If you do not write an equation, all conditions are joined with AND. Two records match only if every condition matches. This is the safest default, but it can miss duplicates that differ in one field.
Suppose you build a Contact rule with these conditions:
- First Name, fuzzy
- Last Name, exact
- Email, exact
- Mailing Zip/Postal Code, exact
Several equations are possible, and each one gives a different result:
| Equation | Meaning | Typical result |
|---|---|---|
| `1 AND 2 AND 3 AND 4` | Everything must agree | Few false positives, many missed duplicates |
| `(1 AND 2) OR 3` | Same person by name, or same email | Catches people who changed address or spelled a first name differently |
| `(1 AND 2 AND 4) OR 3` | Name and zip, or same email | Stricter name path, same email path |
Check the exact controls for entering the equation in your release. In the rule editor it is usually a custom logic option next to the condition list.
Blank fields: the main source of surprises
Blank handling is the most common reason a rule behaves differently from what you expected. There are two opposite failures.
Missed duplicates
Take the equation (1 AND 2) OR 3 on Contacts. A new contact has First Name "Jon", Last Name "Smith" and no email. An existing contact has "John Smith" and no email. The name path matches, so the pair is flagged. The email condition does not help here, and you do not need Match Blanks for it.
Now take the all-AND equation 1 AND 2 AND 3 AND 4. Neither record has a Mailing Zip. With Match Blanks off, condition 4 is "no match", so the whole equation is false. The pair is never flagged, even though names and email agree. If zip codes are often empty in your data, either remove that condition from the required path or turn on Match Blanks for it.
False positives
Match Blanks is dangerous in an OR path. Consider (1 AND 2) OR 3 with Match Blanks checked on Email. Any two contacts with no email now satisfy condition 3, so the equation is true for them. If a large share of your contacts have no email, almost every pair in that group is flagged.
A good habit:
- Leave Match Blanks off on identifying fields such as Email, Phone and External ID. An empty value says nothing about identity.
- Turn it on only for supporting fields in an
ANDpath, where an empty value should not veto an otherwise strong match.
Fuzzy methods and blanks
Fuzzy comparison needs text to compare. If one side is blank, there is nothing to score, so the condition is "no match" regardless of the method. Match Blanks is the only thing that can make two blank values count as equal.
Testing blank behavior from Apex
You can check how an active rule treats blanks without saving a record, using Datacloud.FindDuplicates. This assumes the Contact duplicate rule that uses your custom matching rule is active.
Contact blankEmail = new Contact(
FirstName = 'Jon',
LastName = 'Smith'
);
List<Datacloud.FindDuplicatesResult> results =
Datacloud.FindDuplicates.findDuplicates(new List<Contact>{ blankEmail });
Integer total = 0;
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('Matched: ' + matchRecord.getRecord());
total++;
}
}
}
}
System.debug('Matches found: ' + total);Run it in Execute Anonymous with the debug log open. Run it again after you change Match Blanks and reactivate the rules. If the count jumps, you have probably created the false-positive pattern above.
Design checklist for an equation
- List the combinations of fields that would convince a person two records are the same. Each combination becomes one
ANDgroup. - Join the groups with
OR. - For each field, decide whether an empty value should count as agreement. The default answer is no.
- Keep the equation as short as you can. Every extra
ORpath is another way to flag unrelated records. - Test with real record pairs, including ones with blanks, before you activate.
Common errors
- Assuming blank equals blank. It does not unless Match Blanks is checked on that condition.
- Mixing up numbers. Equation numbers follow the condition order. If you reorder or delete conditions, review the equation.
- Too many
ORpaths. Each path should be strong enough to stand alone. - Relying on one weak field. City or State alone is not an identifying field, so never give it its own
ORpath. - Unbalanced parentheses.
1 AND (2 OR 3will not save. Count your brackets.
Exercise
A Lead matching rule uses conditions 1 = Last Name (exact), 2 = Company (fuzzy) and 3 = Phone (exact), with the equation (1 AND 2) OR 3. An admin checks Match Blanks on Phone. Many unrelated leads that have no phone number are now flagged as duplicates. Why does this happen, and what is the fix?
Show answer
With Match Blanks on, two leads that both have an empty Phone make condition 3 a match. Because condition 3 stands alone on one side of the OR, the whole equation is true for them, whatever their names and companies are. The fix is to uncheck Match Blanks on Phone so that an empty phone no longer counts as agreement. The name and company path (1 AND 2) still catches real duplicates.
Exercise
Your Contact rule uses 1 AND 2 AND 3, where 3 is Mailing Zip (exact) with Match Blanks off. Two contacts have the same name and email, but neither has a zip code. They are not flagged. Give two ways to fix it.
Show answer
Option one: check Match Blanks on condition 3, so two blank zips count as a match inside the AND. Option two: change the equation to (1 AND 2), or to (1 AND 2) OR (1 AND 2 AND 3), so the zip is not required. Test either change on a few real pairs before activating.