Sub topic 8
Choosing actions: allow, block, alert and report
A duplicate rule needs two things: a matching rule that finds likely duplicates, and an action that says what happens when it finds one. This chapter covers the action settings. It assumes you can open Setup and edit a duplicate rule, and that you know how a duplicate rule refers to a matching rule. The Apex section assumes basic Apex.
The two decisions on every rule
A duplicate rule makes its decisions separately for two events:
- Action on create: what happens when a user or process inserts a record.
- Action on edit: what happens when a user or process updates an existing record.
You can choose different behavior for each. A common pattern is to block on create and only alert on edit. Many orgs already hold duplicates, and a strict edit action would stop users from fixing unrelated fields on those records.
For each event you pick a main action, Allow or Block. When you pick Allow, you can add two options, Alert and Report.
| Setting | What the user sees | Is the record saved? | Is it recorded for review? |
|---|---|---|---|
| Allow, no options | Nothing | Yes | No |
| Allow with Alert | A warning that lists the likely duplicates | Yes, after the user chooses to save | No |
| Allow with Report | Nothing | Yes | Yes, in a duplicate record set |
| Allow with Alert and Report | The warning | Yes, after the user chooses to save | Yes |
| Block | An error that lists the likely duplicates | No | See the note below |
In Setup, the exact controls shown for Block can differ by release and by object, so check the rule editor in your own org. Setting Allow with neither option makes the rule do nothing visible, so it is rarely useful.
What each action does
Allow
Allow never stops a save. Alone, it is only useful as a placeholder. Combined with Alert or Report, it lets you find duplicates without interrupting work.
Alert
Alert shows a message when the matching rule finds a likely duplicate. In the Lightning Experience UI, the message includes the matching records, so the user can open one and decide whether to proceed. You write the alert text yourself. Make it say what to do, for example "A similar contact already exists. Open it and update it instead of creating a new one."
Alert is a warning. The user can still save. This makes it a good fit when your matching rule is fuzzy and may flag records that are not true duplicates.
Block
Block rejects the save and shows your message. Use it when a duplicate is clearly wrong and your matching rule is precise, such as an exact match on a unique email address. A block based on a loose fuzzy match will frustrate users, because they cannot save a legitimate record.
Report
Report records the match instead of interrupting the user. When a rule with Report finds a match, Salesforce creates or updates a duplicate record set. The set contains duplicate record items that link each matched record to the set. You can review these through the Duplicate Record Sets tab or through reports. Reporting is the safest first step in a clean-up project, because it gathers evidence without changing user behavior.
Choosing an action
The right action depends on two things: how reliable the matching rule is, and how costly a duplicate is.
A practical rollout order:
- Start with Allow and Report. Review the duplicate record sets for a few weeks.
- Check the matches for false positives. If the matching rule flags records that are not duplicates, adjust it before you change the action.
- Move to Allow with Alert so users see the warning.
- Move to Block only for cases where an exact, trustworthy match exists.
Create versus edit
Different actions for create and edit are normal, and often wise:
- Create: this is the best place to prevent duplicates. Blocking or alerting here stops a duplicate before it exists.
- Edit: be gentler. Existing duplicates may already be in the org, and a Block on edit can stop a user from changing something unrelated, such as a phone number, on a record that matches another record.
A reasonable default is Block (or Alert) on create and Alert plus Report on edit.
How actions affect the API and Apex
Actions apply to saves from code, integrations, and data loads, not only the UI. There are no user dialogs there, so the behavior differs:
- Block: the save fails with a duplicate error.
- Alert: by default, the save also fails with a duplicate error, because no user is present to acknowledge the alert. The caller can acknowledge it by setting
DuplicateRuleHeader.allowSavetotrue. - Report: matches are recorded without interrupting the save.
In Apex, use Database.insert with allSuccess set to false, or a DML options object, so that a duplicate error does not throw an exception that rolls back the whole transaction. The following example separates an alert from a block by checking isAllowSave() on the duplicate result.
Account acct = new Account(Name = 'Acme Corporation', BillingCity = 'Chicago');
Database.SaveResult saveResult = Database.insert(acct, false);
if (!saveResult.isSuccess()) {
for (Database.Error err : saveResult.getErrors()) {
if (err instanceof Database.DuplicateError) {
Database.DuplicateError dupError = (Database.DuplicateError) err;
Datacloud.DuplicateResult dupResult = dupError.getDuplicateResult();
System.debug('Rule: ' + dupResult.getDuplicateRule());
if (dupResult.isAllowSave()) {
// The rule is Allow with Alert. Save again and acknowledge the alert.
Database.DMLOptions dmlOptions = new Database.DMLOptions();
dmlOptions.DuplicateRuleHeader.allowSave = true;
Database.SaveResult retry = Database.insert(acct, dmlOptions);
System.debug('Saved despite alert: ' + retry.isSuccess());
} else {
// The rule is Block. Do not retry.
System.debug('Blocked by duplicate rule.');
}
}
}
}Reviewing what Report collected
After a rule with Report runs for a while, query the duplicate record sets it created:
SELECT Id, DuplicateRuleId, RecordCount
FROM DuplicateRecordSet
ORDER BY CreatedDate DESC
LIMIT 20Each set holds the records that matched. The next chapters cover how to review sets and merge their records.
Common mistakes
- Using Block with a fuzzy matching rule. Fuzzy matches can flag legitimate records, and Block gives users no way past them.
- Forgetting Report. An Alert-only rule leaves no history, so you cannot measure how often duplicates occur.
- Assuming an alert works in integrations. An API client that does not set
allowSavewill see failures where a user would see only a warning. - Using the same action for create and edit. This often creates friction on old data that you did not intend.
- Vague alert text. Users click through warnings they cannot understand.
Exercise
A rule matches Contacts on exact email address. A nightly integration inserts Contacts through the API, and the rule's create action is Allow with Alert. The integration now reports failed inserts that mention a duplicate error. Why does this happen, and give two ways to fix it.
Show answer
With Allow and Alert, a save from the API fails with a duplicate error unless the caller acknowledges the alert, because no user is present to click Save. Fix 1: set DuplicateRuleHeader.allowSave to true in the integration's DML options or API header, so alerts are acknowledged and the records save. Fix 2: change the create action to Allow with Report, or to Block if the integration should never create duplicates. Block would keep failing the inserts, but it states the intent clearly. Report lets all records save and records the matches for later review.
Exercise
You are introducing a new duplicate rule that uses a fuzzy matching rule on Accounts. You do not yet know how many false positives it produces. Which action would you pick first on create and on edit, and what is your next step after a few weeks?
Show answer
Pick Allow with Report on both create and edit, so no user is interrupted and matches are recorded in duplicate record sets. After a few weeks, review the sets for false positives and tune the matching rule if needed. Then move create to Allow with Alert, and consider Block only if the matches prove precise.