DuplicateRule defines an object's duplicate-management policy for record inserts and updates. It combines matching-rule associations, criteria that determine when the policy applies, record-sharing behavior, and actions that allow or block a save. Matching can compare records within the same object or across different objects.
A MatchingRule defines what constitutes a match. DuplicateRule decides what happens after a match: block the operation, alert the user, or include the operation in duplicate reporting. DuplicateRule metadata is also distinct from the similarly named runtime DuplicateRule sObject, the record-oriented API object used to view rule details.
Key Elements
| Element | What the Element Controls |
|---|---|
isActive |
The execution gate. When true, the rule detects duplicates; when false, it has no effect. |
actionOnInsert |
The insert policy: Allow or Block. With Allow, operationsOnInsert determines whether to alert or report. |
actionOnUpdate |
The update policy: Allow or Block. It is independent of the insert policy. |
operationsOnInsert |
A multivalued setting for an allowed insert. Documented values are alert and report; either or both can be included. |
operationsOnUpdate |
A multivalued setting for an allowed update. Documented values are alert and report; either or both can be included. |
alertText |
The message displayed or returned when alerting applies. It does not enable alerting by itself. A value is permitted only when at least one save action is Allow. |
securityOption |
EnforceSharingRules respects record sharing. BypassSharingRules ignores sharing for duplicate management, but other access restrictions still apply. |
sortOrder |
At the top level, determines the order in which duplicate rules are applied. The identically named element inside a filter item orders filter items instead. |
duplicateRuleFilter, booleanFilter
|
The criteria that determine whether the rule applies to a record. booleanFilter combines the individual conditions; it does not define the matching algorithm. |
duplicateRuleFilterItems |
The individual filter conditions. Each item's table identifies the object containing field; operation selects the comparison, and value supplies a literal comparison value. |
duplicateRuleMatchRules |
One or more matching-rule associations used to identify duplicates. |
matchRuleSObjectType, matchingRule
|
The matching target object and the associated matching rule. matchingRule contains the matching rule's developerName, not a record ID. |
objectMapping |
Maps the rule's object to the matching target. inputObject is the object associated with the duplicate rule; outputObject must match matchRuleSObjectType. |
mappingFields |
Pairs fields across the mapping. Each inputField belongs to inputObject, and each outputField belongs to outputObject. |
Behavior and Constraints
Activation and ordering. An inactive rule has no effect, regardless of its actions, message, or matching configuration. The top-level sortOrder controls duplicate-rule application order. Do not confuse it with duplicateRuleFilterItems.sortOrder, which orders conditions inside the filter.
Allow, alert, and report are separate decisions. Insert and update policies can differ:
-
Allow with alert: The UI displays
alertTextin a dialog. The user can continue with the save or cancel it. In the documented API save flow, the caller receives a duplicate response and must setallowSaveinDuplicateRuleHeadertotrue, then reissue the request to complete the save. - Allow without alert: The save proceeds without the duplicate alert or API duplicate error.
- Block: The operation is prevented and an error is returned.
The report operation adds the insert or update to the report of duplicates. It is separate from prompting the user, so reporting does not itself enable an alert. operationsOnInsert and operationsOnUpdate are multivalued settings, not single combined action strings.
Alert text has a validation constraint. Salesforce sends alertText only when the rule is active. Supplying text does not enable alerting. At least one of actionOnInsert or actionOnUpdate must be Allow to supply a value; adding or updating a component with text when both actions are Block causes a validation error.
Sharing changes detection outcomes. With EnforceSharingRules, if the existing duplicate is hidden from the running user by record sharing, the insert or update proceeds without a duplicate message. With BypassSharingRules, duplicate management ignores sharing rules, but it does not bypass all security controls. Identical record values can therefore produce different outcomes for users with different sharing access.
Filters and matching have different roles. Salesforce applies the rule only when the record meets duplicateRuleFilter. The associated matching rules then determine what constitutes a match. Filter field references resolve against each item's table, not automatically against the object named in the component file.
Cross-object matching does not invoke the target object's policies. For example, a Contact duplicate rule can map Contact fields to corresponding Lead fields. A mapping can also relate fields within the same object. When the DuplicateRule API uses an ObjectMapping, duplicate rules belonging to outputObject are ignored. The mapping supplies field correspondence; it does not call the target object's duplicate-rule policies.
Deployment and Retrieval
DuplicateRule supports Metadata API deployment and retrieval. Components use the .duplicateRule suffix and reside in duplicateRules/. The type supports the * wildcard in a package.xml manifest. See the DuplicateRule Metadata API reference.
The component name follows <objectName>.<componentName>. For example, duplicateRules/Account.Standard_Account_Duplicate_Rule.duplicateRule identifies a rule associated with Account. Preserve namespaces and the complete component name: after removing the directory and metadata extension, the text before the first period identifies the associated object. This can be a standard or custom object.
Required top-level settings include the insert and update actions, their operation settings, the filter, matching-rule associations, activation state, sharing option, and rule order. description and masterLabel are also required. The customer-supplied description is not visible in the UI; masterLabel is the rule's internal label.
Resolve dependencies in their own object contexts: filter fields against table, input fields against inputObject, output fields against outputObject, and the matching rule by its developer name. A change to matching logic or a mapped field can change duplicate behavior even when the rule's Allow and Block settings remain unchanged. The name-based object association does not, by itself, require the object and rule to be deployed or deleted together.
For automated removal of standard duplicate rules during scratch-org setup, a 2021 community answer proposed a destructive metadata deployment, meaning a deployment that explicitly deletes named components:
- List
DuplicateRulemetadata and collect the returnedfullNamevalues. - Put the selected names under the
DuplicateRuletype indestructiveChanges.xml. - Include a
package.xmlwith no component entries and deploy the deletion package through Metadata API.
This is a community-proposed removal workflow, not a requirement to remove standard rules before every deployment. Setting isActive to false disables a rule rather than deleting its metadata.
Relationships
The dependencies that affect behavior are the associated matching rule, the objects involved in filtering and mapping, and the fields resolved within those objects. The filter, matching-rule association, and object-mapping structures are nested parts of the duplicate rule.
Name-based association: CustomObject is the metadata context identified by the <objectName> prefix in the component name. This association is separate from the element references below and does not establish a mandatory deployment or deletion sequence.
References
-
CustomField:field,inputField,outputField. -
CustomObject:inputObject,matchRuleSObjectType,outputObject,table. -
MatchingRule:matchingRule, using the matching rule'sdeveloperName.
Documentation Inconsistencies
Salesforce documents the operation values as lowercase alert and report, but its XML example uses Alert and Report. The documentation does not establish that the two casings are interchangeable.
Reported Issues
-
An unchanged save might not process pre-existing duplicates. In a 2021 report about records last edited before rule activation, saving records without changing fields did not create
DuplicateRecordSetrecords. The author reported that duplicate logic ran when fields used by the matching rule actually changed. This is a diagnostic condition for update behavior, not a verified method for backfilling duplicate results. Existing-record update report. -
A DuplicateRule deployment error can accompany a referenced matching-rule failure. An August 2024 report showed "Before you change a matching rule, you must deactivate it" for
MatchingRule, alongside an unexpectedDuplicateRuleerror. The author reported recovery by deleting the duplicate rule, then the matching rule, and redeploying. That incident-specific recovery does not establish that every edit requires deletion. Matching-rule deployment recovery. - An existing subscriber rule can affect a managed-package upgrade. A February 2025 report described adding a packaged duplicate rule to a custom object that already had a subscriber duplicate rule. The upgrade failed with "SortOrder must be in sequential order from 1." Deactivating the existing rule did not resolve the failure. The author linked a known issue and reported deletion as the only workaround at that time; this does not establish that deletion remains necessary. Managed-package ordering report and linked known issue.
-
A runtime sObject PATCH failure is not a metadata deployment failure. An unanswered January 2025 report attempted to change
IsActiveby sending a PATCH with a record ID to the sObjectsDuplicateRuleendpoint. It returned "entity type cannot be updated: Duplicate Rule". That observation concerns the runtime endpoint, not DuplicateRule metadata deployment, and does not establish whether other REST mechanisms are available. REST update report. -
A successful deployment was reported not to reactivate manually disabled rules. In an unanswered 2020 report, rules manually deactivated in a sandbox stayed disabled after a manifest deployment whose definitions contained
isActiveset totrue. No cause or resolution was established in the discussion. This report does not change the defined meaning ofisActive. Activation-state deployment report. -
Standard-rule removal can be approached as metadata deletion rather than record deletion. A 2021 community answer about automating scratch-org setup proposed listing rule metadata, generating
destructiveChanges.xmlfrom its full names, and deploying the deletion package. The answer proposed the workflow; it did not establish a universal prerequisite to delete standard rules. Automated removal proposal.
Common Questions
How do I retrieve DuplicateRule metadata?
Use the DuplicateRule type in package.xml. The type supports *, and component names follow <objectName>.<componentName>, such as Account.Standard_Account_Duplicate_Rule. Files reside in duplicateRules/.
Why does Allow still return a duplicate error through the API?
When the corresponding operation includes alert, the documented API flow returns a duplicate response. To complete an allowed save, set DuplicateRuleHeader.allowSave to true and reissue the request. Without alerting, an allowed save proceeds without the duplicate error.
Why does the same duplicate get blocked for one user but not another?
Check securityOption and record-sharing access. With EnforceSharingRules, a matching existing record hidden from the user does not cause a duplicate message or prevent the save. BypassSharingRules ignores sharing for duplicate management, but other access restrictions still apply.
Why does alertText cause a deployment validation error?
A value for alertText is permitted only when actionOnInsert, actionOnUpdate, or both are Allow. Supplying it when both actions are Block causes a validation error when adding or updating the component.
Does editing an existing record always detect old duplicates?
Do not assume that an unchanged save processes pre-existing duplicates. A 2021 community report found no duplicate-set creation from unchanged saves and reported execution when matching-rule fields actually changed. That report is a diagnostic condition, not a verified backfill mechanism.