4

I've found how to reference Matching Rules by name in Metadata, but that's only the logic to identify a duplicate. I'm looking for how to reference Duplicate Rules by name in Metadata, which will dictate what to do when a duplicate is found.

Does anyone know if it's supported in Metadata yet, and if so what's the name to reference it?

XML from retrieving

<types>
    <members>*</members>
    <name>MatchingRule</name>
</types>

<MatchingRules xmlns="http://soap.sforce.com/2006/04/metadata">
<matchingRules>
    <fullName>Custom_Contact_Rule1</fullName>
    <booleanFilter>((1 AND 2) OR 3 OR 4) AND 5</booleanFilter>
    <label>Custom Contact Rule1</label>
    <matchingRuleItems>
        <blankValueBehavior>NullNotAllowed</blankValueBehavior>
        <fieldName>FirstName</fieldName>
        <matchingMethod>FirstName</matchingMethod>
    </matchingRuleItems>
    <matchingRuleItems>
        <blankValueBehavior>NullNotAllowed</blankValueBehavior>
        <fieldName>LastName</fieldName>
        <matchingMethod>LastName</matchingMethod>
    </matchingRuleItems>
    <matchingRuleItems>
        <blankValueBehavior>NullNotAllowed</blankValueBehavior>
        <fieldName>Email</fieldName>
        <matchingMethod>Exact</matchingMethod>
    </matchingRuleItems>
    <matchingRuleItems>
        <blankValueBehavior>NullNotAllowed</blankValueBehavior>
        <fieldName>Phone</fieldName>
        <matchingMethod>Phone</matchingMethod>
    </matchingRuleItems>
    <matchingRuleItems>
        <blankValueBehavior>NullNotAllowed</blankValueBehavior>
        <fieldName>AccountId</fieldName>
        <matchingMethod>CompanyName</matchingMethod>
    </matchingRuleItems>
    <ruleStatus>Active</ruleStatus>
</matchingRules>


I would expect to be able to retrieve Duplicate Rule data as well, which specifies the following pieces of data

  • If sharing rules are enforced
  • If users can bypass the creation on create or edit
  • How the fields are mapped
5
  • Isn't matching rule is what used to identify the duplicates in an object? Or, are you looking for how to invoke one of these defined matching rules and get the duplicates? Commented Feb 24, 2015 at 17:15
  • You are correct - a MatchingRule defines logic to identify the duplicate in an object. I'm looking for DuplicateRule, which defines the logic to handle the duplicate once found. Very similar to WorkflowRule and an action on the WorkflowRule - like FieldUpdate. I will update my question to show the xml pulled from MatchingRules as well as what data I'm looking to pull as well.
    – zainogj
    Commented Feb 24, 2015 at 17:22
  • As of today, it seems to be unsupported. There is an idea for it on the IdeaExchange.
    – zainogj
    Commented Feb 24, 2015 at 19:07
  • Thanks. But be aware that changesets are different features than metadata api, even though both are for deployment. There are many components which are supported in Metadata api but not in changeset Commented Feb 24, 2015 at 19:14
  • Does anyone know if it's supported by DX deployments? Doesn't seem to be working for me. I can't retrieve Duplicate Rules, and I can retrieve but not deploy Matching Rules. Wanting to avoid converting my project to mdapi format just for deployment of these Commented Jan 25, 2021 at 20:56

3 Answers 3

1

Migrating Duplicate Rules via Metadata API is officially supported starting with API version 42.0 (Spring '18). See the official documentation on how to use: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_duplicaterule.htm

4
  • Does anyone know if it's supported by DX deployments? Doesn't seem to be working for me. I can't retrieve Duplicate Rules, and I can retrieve but not deploy Matching Rules. Wanting to avoid converting my project to mdapi format just for deployment of these Commented Jan 25, 2021 at 20:56
  • DuplicateRule Metadata Type is fully supported by SFDX Source Format. Also see mdcoverage.secure.force.com/docs/metadata-coverage/51, which states this officially. We are doing force:source:deploy a few dozen times a day...
    – ebi
    Commented Jan 25, 2021 at 21:05
  • And you've personally seen Duplicate Rules retrieve & Matching Rules deploy successfully in these daily deployments? I've gotten Matching Rules to retrieve into a new matchingRules folder in the SFDX source folder via force:source:retrieve, but they aren't deploying (nor erroring upon deploy). Can't even get Duplicate Rules to retrieve Commented Jan 26, 2021 at 0:57
  • Sure, both Metadata types are retrieved from and deploying into Scratch Orgs and Sandboxes regularly. I also just tested sfdx force:source:retrieve -m DuplicateRule,MatchingRules -u <org> as well as sfdx force:source:deploy -m DuplicateRule,MatchingRules -u <org> successfully. NOTE: The Metadata Types are named inconsistently (DuplicateRule = singular, MatchingRules = plural)!
    – ebi
    Commented Jan 26, 2021 at 10:11
2

As mentioned on this idea, this is not included in the metadata and Salesforce is currently planning to add it to the roadmap. I'll update this answer once I hear that it's been released.

1
  • absence of this feature doesn't pass the straight-face test :-(
    – cropredy
    Commented Jun 8, 2016 at 0:28
0

It is now supported...for instance, if you have created a matching rule with a DeveloperName named "Same_Account_Name", this is the way you use to get it:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Account</members>
        <name>MatchingRules</name>
    </types>
    <version>55.0</version>
</Package>

It will retrieve the following source:

<?xml version="1.0" encoding="UTF-8"?>
<MatchingRules xmlns="http://soap.sforce.com/2006/04/metadata">
    <matchingRules>
        <fullName>Same_Account_Name</fullName>
        <label>Same Account Name</label>
        <matchingRuleItems>
            <blankValueBehavior>NullNotAllowed</blankValueBehavior>
            <fieldName>Name</fieldName>
            <matchingMethod>CompanyName</matchingMethod>
        </matchingRuleItems>
        <ruleStatus>Active</ruleStatus>
    </matchingRules>
</MatchingRules>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .