Sub topic 8
Choosing actions: allow, block, alert and report
This chapter assumes you know what matching rules and duplicate rules are, and that you can open Duplicate Rules in Setup. Here you will choose what happens when a matching rule finds a duplicate.
The two settings
A duplicate rule has separate action settings for Create and Edit. For each one, you choose Allow or Block. You can then add Alert, Report, or both, depending on that choice.
| Action | What the user sees | What is stored |
|---|---|---|
| Allow | The save succeeds with no message. | Nothing extra. |
| Allow with Alert | A warning lists the possible duplicates. The user can save anyway. | Nothing extra. |
| Allow with Report | The save succeeds with no message. | A duplicate record set entry. |
| Block | An error lists the possible duplicates, and the save fails. | Nothing extra. |
| Block with Report | The same error. | A duplicate record set entry. |
Alert is a warning for a person. Report is a log for administrators. Report writes to duplicate record sets, which you can review and report on later. The two are independent, so a rule can do either or both.
How a save flows through a rule
Choosing an action
- Block on create works when a duplicate is clearly wrong, such as the same email address on two Contacts. It is the strictest option and the most likely to frustrate users when the matching rule is loose.
- Alert on create works when matches are probable but not certain, such as fuzzy name matches. The user decides.
- Allow with Report works when you are tuning a new rule. Nobody is interrupted, and you can see what the rule would catch.
- Edit often needs a softer setting than Create. Blocking edits can stop users from changing records that were already duplicates before the rule existed.
A common path is to start with Allow and Report, review the duplicate record sets, tighten the matching rule, and then move Create to Alert or Block.
Actions and code
Block and Alert both stop a save made through the API or Apex. The failure comes back as a Database.DuplicateError. A rule that allows with an alert can be acknowledged by setting allowSave:
Account acct = new Account(Name = 'Acme Corporation', BillingCity = 'Chicago');
Database.DMLOptions dmlOptions = new Database.DMLOptions();
dmlOptions.DuplicateRuleHeader.allowSave = true;
Database.SaveResult saveResult = Database.insert(acct, dmlOptions);
System.debug('Saved despite alerts: ' + saveResult.isSuccess());This only overrides rules whose action is Allow with an alert. A Block rule still fails the save.
Exercise
A team wants a new fuzzy Lead rule to run for two weeks without interrupting anyone, so they can judge how accurate it is. Which action should they choose, and where do they look at the results?
Show answer
Choose Allow with Report on both Create and Edit, with Alert turned off. Users are not interrupted, and each match is recorded as a duplicate record set. They review the results in the duplicate record sets and in reports on them.