2

We have a matching rule on Contact which defines a dupe using the following logic: A fuzzy match on the first Name and Last Name and EITHER a fuzzy match on address (using street or postcode) OR a custom fuzzy match on birthday.

We've achieved the fuzzy match on Birthday by building a trigger which separates the birthdate into 3 separate integer fields (day, month and year) and considering a match on at least 2 of these components as a duplicate.

We have duplicate rules set up to compare a new Custom Object with Contacts and have set up our mappings accordingly. When attempting to enter one of these custom records using the user interface, a potential duplicate is identified as expected. We wanted to replicate this in Apex as part of a process which will allow users to link these custom records to the relevant Contact record.

We're finding that the apex will return dupes based upon the address fields, but it won't work when based upon the birthdate information:

Custom_Object__c record = new Custom_Object__c(
                            First_Name__c = 'Arthur',
                            Last_Name__c = 'Smith',
                            BirthDate__c = date.newInstance(1934, 11, 20),
                            BirthDate_Day__c = 20,
                            BirthDate_Month__c = 11,
                            BirthDate_Year__c = 1934,
                            Street__c = null,
                            PostCode__c = null);

I'm setting the date components separately, as the matching rules use these fields (and they're not set by trigger unless I run a DML operation). If I run the FindDuplicates method for the above SObject, this does not return matches. However, if I populate the postcode to match an existing Contact record, matches are returned. If I remove the date components and leave the postcode with the matching value, matches are returned.

I've checked and triple checked that the Contact I expect to match with is in the system with the data required. I've also confirmed it by entering this data into the UI and getting a match.

I'm uncertain why the integer components of this SObject may not be triggering a match in the duplicate rules.

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.