Sub topic 9
Sharing rules and conditions that limit a duplicate rule
A duplicate rule does not always compare a record against every record in the org, and it does not always run. Two settings on the rule control this. Record-Level Security decides which existing records the rule can compare against. Conditions decide whether the rule runs at all for a given save. Both can cause "why wasn't this flagged?" problems, so this chapter covers how each works and how to choose between the options.
This chapter assumes you can create a duplicate rule and attach a matching rule to it. It also assumes you understand the basics of Salesforce sharing: organization-wide defaults, role hierarchy, and sharing rules that decide which records a user can see.
Where these settings live
Both settings are on the duplicate rule's detail page in Setup, under Duplicate Rules. The rule has these parts:
- Object, rule name and description.
- Record-Level Security, which has two options: enforce sharing rules, or bypass sharing rules.
- Actions for create and edit, covered in the previous chapter.
- Matching Rules, which names the rule that does the comparing.
- Conditions, which filters when the rule runs.
The matching rule defines what "alike" means. The two settings in this chapter define which records are compared and which saves trigger the comparison.
Record-level security: enforce or bypass sharing
A duplicate rule runs in the context of the user who saves the record. The Record-Level Security setting tells it whether to respect that user's visibility.
| Setting | What the rule compares against | Typical result |
|---|---|---|
| Enforce sharing rules | Only records the saving user can see through sharing | Fewer matches. Duplicates owned by people the user cannot see are missed. |
| Bypass sharing rules | All records of the object, regardless of sharing | More matches. The user may be told a duplicate exists without being able to open it. |
Enforce sharing rules
Suppose Accounts are Private in the organization-wide defaults. A rep in the East team creates "Acme Corporation". A rep in the West team already owns an "Acme Corporation" that the East rep cannot see. If the duplicate rule enforces sharing, the East rep's save finds no match, and a second Acme is created.
Use this option when the data really is meant to be partitioned. Examples are separate business units that must not know about each other's customers, or territories where the same company legitimately appears twice.
Bypass sharing rules
With bypass, the same save finds the West rep's Acme. The rule's action then runs. If the action is Block, the East rep cannot create the account. If it is Allow with an alert, the rep sees a warning.
This option catches the most duplicates, which is usually the goal of duplicate management. It has a cost. The user is told that a matching record exists, but sharing still controls what they can see about it. Salesforce does not expose the hidden record's details just because the rule bypassed sharing. The user sees that a duplicate exists, and may be unable to open it, see its owner, or merge it.
Choosing between them
Ask what you want to happen when the duplicate is invisible to the user:
- If you want to prevent the second record at any cost, use bypass.
- If you accept that separate teams may keep separate copies, use enforce.
- If you use bypass with Block, define who resolves the conflict. Otherwise users will be stuck, and they will ask for the rule to be turned off.
A common compromise is to bypass sharing but use Allow with an alert, with reporting on. Users can still save, and an administrator reviews the duplicate record sets later.
Conditions: deciding when the rule runs
Conditions are optional filters on the duplicate rule. If you add none, the rule runs on every create or edit of that object by every user. When you add conditions, the rule runs only when they are true. If they are false, the save proceeds as if the rule did not exist.
Conditions can look at fields on the record being saved. They can also look at attributes of the user who is saving it, such as the user's profile. This gives you two kinds of limit:
| Kind of condition | Example | Why you might use it |
|---|---|---|
| Record-based | Run only when Billing Country equals United States | Different regions use different rules, or the matching rule's fields are only reliable for some data |
| User-based | Run only when the current user's profile is not Integration User | Let a data load skip the rule while normal users are still checked |
You can add several conditions and combine them with filter logic, for example 1 AND (2 OR 3).
Why a rule may not fire
Conditions are a common reason a duplicate is "missed". Before you rework a matching rule, check these in order:
- Is the rule active? An inactive rule never runs.
- Do the conditions pass for this save? The record and the user must both satisfy them.
- Can the saving user see the existing record? This matters when sharing is enforced.
- Does the matching rule match these two records? Only now look at fields, exact versus fuzzy methods, and blank fields.
Doing the checks in this order saves time. Most missed duplicates come from steps 1 to 3, not from the matching rule itself.
How the checks fit together
On every create or edit, Salesforce evaluates the rule in a fixed order. The diagram shows where each setting acts.
Interaction with other features
- Several rules on one object. Each active duplicate rule is evaluated separately, and each can have its own sharing setting and conditions. Two rules on Account can behave differently for the same user. Rule order is covered in the chapter on activation.
- Cross-object rules. A rule on Lead that compares against Contacts applies the sharing setting to the records it compares against, in the same way. The next chapter covers this.
- Integrations and data loads. Loads run as a user. A user-based condition, or the allow-save option covered in the Apex chapters, lets trusted loads skip or acknowledge the rule. Do not disable a rule just to run an import.
- Reports. Duplicate record sets are created when a rule reports matches. If sharing is enforced, a set reflects only what the saving user could see at that moment. A later save by a user with wider visibility may find more matches.
Common mistakes
- Leaving sharing enforced and then concluding the matching rule is broken, when the matching record was simply not visible.
- Choosing bypass with Block and no way for blocked users to reach the existing record.
- Adding a condition on a field that is often empty. When the field is empty the condition is false, so the rule never runs for those records.
- Scoping a rule to a profile, then adding users with a different profile who are never checked.
Exercise
A rep in the West team cannot see an existing Account "Globex Ltd" owned by the East team. The rep creates a new "Globex Ltd" and no alert appears, although the matching rule would match the two records. The duplicate rule is active and has no conditions. What is the most likely cause, and what would you change if the business wants the duplicate caught?
Show answer
The duplicate rule is set to enforce sharing rules, so it compares only against records the West rep can see. The East team's Globex Ltd is not a candidate, so no match is found. To catch it, change Record-Level Security to bypass sharing rules. Because the rep still cannot open the hidden record, also decide who resolves the conflict, for example by using Allow with an alert and reviewing the duplicate record sets, or by giving blocked users an escalation path.
Exercise
You want a duplicate rule on Contact to run for all users except the integration user that loads data nightly. Which part of the rule do you use, and in what order do you troubleshoot if a normal user's duplicate is still not flagged?
Show answer
Use a user-based condition, for example "current user's profile is not Integration User". For troubleshooting, check in order: whether the rule is active, whether the conditions pass for that user and record, whether the user can see the existing record under the sharing setting, and finally whether the matching rule matches the two records.