2

I've run into a sticky situation for a client in which they are unable to run a duplicate job broadly in their org without it failing due to it being a HUGE org with tens of millions of records. This is a known issue in Salesforce. The "workarounds" they prescribe in this article however are super weak sauce and far from sufficient.

This is a major issue for existing records that pre-dated the creation of this dupe rule, as there is some logic in this org that relies upon duplicate rules having run on a given record before it is processed, so that related duplicate record sets can be evaluated and decisions made based on whether duplicates exist before moving on to other (else) logic.

Long story short, I'm wondering if there is a method in apex somewhere that can be called against a record or set of records so that duplicate rules are evaluated right then and there. E.g. something like:

database.checkForDuplicates(sObject record,Id duplicateRuleId)

I'm not holding my breath but man, something like this would be a lifesaver!

Thanks so much.

1 Answer 1

2

You can use findDuplicatesById to get duplicates and then deal with them in a batch job. Alternatively, you could also just as easily run a single pass over the entire database with the data loader or a batchable class, which would force duplicate calculation to occur as it goes through. Note that there's a limit of 50 Ids you can pass in at once, so make sure that you account for this in your batch class. There's a similar method simply called findDuplicates that accepts a list of records rather than Id values, if you prefer.

3
  • 1
    Thanks @sfdcfox these methods definitely seem to be the answer. Sadly they don't force-create the DuplicateRecordSet/DuplicateRecordItem records which would be ideal but at least they return the proper data to parse through. Can you elaborate though on your Data Loader suggestion? According to my reading (and testing), this only works if you are actually updating a field referenced in the related matching rule, per the "How Rules Operate on Edited Fields" section here: help.salesforce.com/s/… Commented Apr 8, 2022 at 0:27
  • @BrigLarimer I wasn't actually aware of that limitation. That said, a two-pass approach would work. First, update all records using a "fake" update (to some other value), then update them back to the correct values.
    – sfdcfox
    Commented Apr 8, 2022 at 0:55
  • Thanks as always sfdcfox! Commented Apr 8, 2022 at 5:33

You must log in to answer this question.

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