MatchingRule defines the field comparisons used to identify potential duplicate records on a standard or custom object, including Person Accounts. It supplies matching criteria that DuplicateRule can reference; it does not define the complete policy for handling duplicates. An active matching rule alone does not establish which duplicate rules use it or what happens when a match is found.
The singular MatchingRule identifies an individual rule. The plural MatchingRules is the object-level container that holds individual rule definitions. This distinction matters when naming manifest members, retrieving files, and deleting rules.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
Identifies the individual rule within the object's matchingRules entries. For example, an entry can contain AccountMatchingRule, while its individual manifest member is Account.AccountMatchingRule. |
label |
Required. The display name of the matching rule, separate from its deployment identifier. |
matchingRuleItems |
The collection of comparison criteria. Each item selects a field, comparison method, and blank-value behavior. |
fieldName |
Required within each comparison item. Identifies the field to compare. A custom field creates a dependency on that field's metadata. |
matchingMethod |
Required within each comparison item. Allowed values are Exact and the field-oriented fuzzy methods FirstName, LastName, CompanyName, Phone, City, Street, Zip, and Title. Fuzzy comparison identifies similar values rather than requiring an exact comparison. |
blankValueBehavior |
Controls how blanks affect an individual comparison. MatchBlanks permits matching blank values. NullNotAllowed is the default. This setting is not a required-field constraint on stored records. |
booleanFilter |
Combines the individual comparison criteria using Boolean logic. The rule's meaning depends on this logic together with matchingRuleItems, not just the list of fields. |
ruleStatus |
Required. Only Active and Inactive are valid deployment declarations. Other exposed values describe activation or deactivation lifecycle states. |
Behavior and Constraints
Read the criteria as a complete expression. Changing fieldName, matchingMethod, blankValueBehavior, or booleanFilter can change which records qualify as matches. The same field can produce different matches when its method changes from Exact to a fuzzy method.
Blank handling applies to each comparison. Its effect on the overall result depends on the Boolean expression: changing whether one comparison matches can change whether the complete rule matches. NullNotAllowed does not make the compared field mandatory on records.
Lifecycle states are not deployment choices. In addition to Active and Inactive, the status enumeration exposes Activating, ActivationFailed, Deactivating, and DeactivationFailed. Those four values describe lifecycle states and cannot be declared when deploying a package.
A valid ruleStatus does not guarantee that an existing rule can accept a criteria update in its current state. Reported updates to active rules have encountered lifecycle errors even when the submitted status remained Active. The destination rule's state and the duplicate rules that actually reference it affect the choice between an in-place update and replacement.
Activation also does not establish that a consuming duplicate rule is active. Matching criteria and duplicate-handling behavior must be interpreted together. For existing records, an unchanged save is not reliable evidence that the combined duplicate-rule and matching-rule configuration was evaluated.
Deployment and Retrieval
Matching-rule component files use the .matchingRule suffix and reside in the matchingRules directory. The file is named for the associated standard or custom object, not the individual rule. For example, Account rules are contained in matchingRules/Account.matchingRule. Person Account rules use matchingRules/PersonAccount.matchingRule.
The XML document has a MatchingRules root containing matchingRules entries. Each entry carries its own fullName, criteria, label, and status.
-
Retrieve or deploy an individual rule: use the manifest type
MatchingRulewith an object-qualified member such asAccount.AccountMatchingRule. The naming pattern isObjectAPIName.RuleFullName. -
Retrieve all matching-rule containers: use the plural manifest type
MatchingRuleswith the member*. This is the documented wildcard retrieval form.
Do not treat an unchanged Active declaration as proof that an update avoids lifecycle restrictions. The reported failures below involved changes to existing criteria, including a changed booleanFilter and an added comparison item.
The reported replacement workarounds targeted individual MatchingRule components rather than deleting an object-level container. In one case, the reporter first deleted the referencing DuplicateRule, then the matching rule, and redeployed both. These are workarounds for particular failures, not general prerequisites for updating every matching rule.
Relationships
A compared custom field can affect a matching rule, which in turn affects duplicate rules that reference it. Changing the field's role, comparison method, blank handling, or Boolean logic can therefore change the matches available to those duplicate rules. A reference establishes a dependency; it does not prove that the consuming duplicate rule is active.
References
-
CustomField:fieldName, withinmatchingRuleItems.
Referenced By
-
DuplicateRule:matchingRule. The consuming rule'sduplicateRuleMatchRulescollection contains its matching-rule associations.
Reported Issues
-
An active-to-active criteria update can fail with a status-change error. In May 2024, an update failed with "Change the matching rule status separately from other changes" even though both the destination and submitted definitions specified
Active. The update changedbooleanFilterand added amatchingRuleItemsentry. The reporter resolved it by deleting and redeploying the individual matching rule. This does not establish that every criteria update requires replacement. Active-rule update report. -
A matching-rule update can fail alongside a consuming duplicate-rule deployment. In August 2024, a deployment returned "Before you change a matching rule, you must deactivate it" and an unexpected
DuplicateRuleerror. The reporter resolved the problem by deleting the referencing duplicate rule, deleting the matching rule, and redeploying them. The workaround does not make deletion a general update requirement. Deactivation-error report. -
Saving unchanged existing records may not create duplicate record sets. A 2021 answer describing an email-based Contact configuration reported that no-change saves did not create
DuplicateRecordSetrecords, while changes to the compared email values did. The answer attributed this to duplicate-rule evaluation occurring when fields used by the matching rule change. This is reported runtime behavior of the combined configuration, not a guarantee provided by matching-rule activation alone. Existing Contact duplicate-detection discussion. -
Deleting the object-level container can be rejected. An org-cleanup answer updated in 2022 records the error "Matching Rules have to be deleted individually" when attempting to delete
MatchingRules. Its cleanup procedure instead targets individualMatchingRulecomponents. Individual-rule deletion report. -
A direct SOQL relationship query may not expose the duplicate-rule association. Respondents in a 2017 discussion, revisited in 2024, reported no accessible Apex or SOQL relationship for discovering a duplicate rule's matching rules. They pointed to retrieving
DuplicateRulemetadata and inspectingduplicateRuleMatchRulesinstead. This is a reported query-access limitation, not an absence of a metadata dependency. Matching-rule association discussion.
Common Questions
How do I retrieve one matching rule or all matching rules?
For one rule, use MatchingRule with an object-qualified member such as Account.AccountMatchingRule. For the documented wildcard retrieval of all containers, use MatchingRules with *. The component files are named for their associated objects.
Why does deployment fail when the matching rule is already Active?
An existing active rule can encounter lifecycle restrictions during a criteria update even when the submitted ruleStatus remains Active. The reported cases involved status or deactivation errors. Replacement resolved those cases, but it is not established as a requirement for every update.
Does activating a matching rule block duplicate records?
Not by itself. MatchingRule supplies the comparisons used to identify matches. Referencing DuplicateRule definitions determine how detected duplicates are handled, and a metadata reference does not prove that the consuming rule is active.
Does NullNotAllowed make the compared field required?
No. NullNotAllowed is the default blank-handling setting for an individual comparison, not a required-field constraint. Its effect on the complete match must be read alongside booleanFilter.
Why didn't saving existing Contacts create DuplicateRecordSet records?
A no-change save is not reliable evidence that duplicate matching ran. In the reported email-based Contact case, unchanged saves did not create sets, while changes to the compared email values did. That observation concerns the combined duplicate-rule and matching-rule configuration.