0

I've noticed that theDatacloud.FindDuplicates.findDuplicates() method will not return gracefully if there are no active duplicate rules for the object. Instead, it throws an exception

System.HandledException: No active duplicate rules are defined for the Contact object type

Has anyone else run into this? What's the purpose of the success property on the FindDuplicatesResult class if the method throws an exception when it fails? There's no way to detect if there are any active rules on an object?

Here's the code I use to test:

Contact con1 = new Contact(FirstName = 'Already', LastName = 'Exists', Email = 'already@exists.com');
List<Contact> cons = new List<Contact>{con1};
List<Datacloud.FindDuplicatesResult> results = Datacloud.FindDuplicates.findDuplicates(cons);
2
  • I believe we can only use this method when we have active duplicate rules associated with the input sObjects. And also I don't see methods to check if there are active rules on an sObject either. – Vijaya Kapadam Jul 31 '18 at 7:12
  • Yep same behavior here – Scott Morrison Feb 7 '19 at 20:22
2

Late response to the question, but ran into this issue myself and figured I'd post my workaround:

public static Boolean doDuplicateRulesExist(SObject listOfSObjects){
    Boolean duplicateRulesFound = true;

    try {
        Datacloud.FindDuplicates.findDuplicates(listOfSObjects);
    } catch(System.HandledException e){
        if(e.getMessage().startsWith('No duplicate rules are defined for')){
            duplicateRulesFound = false;
        }
    }

    return duplicateRulesFound;
}

Note that if your list of SObjects is mixed it will not tell you which SObject Type in your list of SObjects is problematic - this wasn't a requirement for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.