I have created custom setting to store the ID's of all my active Duplicate Rules. In a test class when I try to assign the custom setting field value I get an error as follows

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Specify a value for the Duplicate Rule ID field.: []

DuplicateRulesId__c rule = DuplicateRulesId__c.getOrgDefaults();
System.debug(rule.DuplicateAccountCustomRuleId__c); // 002ghjgjhgjhgjhg

DuplicateRecordSet drs = new DuplicateRecordSet(
    DuplicateRuleId = String.valueOf(rule.DuplicateAccountCustomRuleId__c)
    // DuplicateRuleId = rule.DuplicateAccountCustomRuleId__c

System.debug(rule.DuplicateAccountCustomRuleId__c) gives me the correct DuplicateRuleID

When i assign it, the enclosed quotes are missing hence, the error.

How do I enclose the DuplicateRuleID retrieved from Custom setting in quotes to avoid the error.

  • 3
    You have to create the custom setting in unit tests, are you doing that? Also seems like you can have multiple duplicate rules so shouldn't you be splitting by comma or semi colon and then looping and adding to the set.. – EricSSH May 23 at 21:22
  • 1
    The quotes are not part of the Id, and should not be part of the string. Something else is going on here. – sfdcfox May 23 at 21:26
  • I am closing this question for now as I tweaked my code to use DeveloperName field instead of accessing DuplicateRule Reord ID from custom setting. – user4947 May 29 at 15:46

Your Answer

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

Browse other questions tagged or ask your own question.