This post was last updated on 11/22/23.
We've all been there: while quickly trying to add a Primary Contact to an Opportunity, we realize there are four different Jack Rogers contact records associated with the Burlington Textiles Corp of America account. Ugh.
Duplicate management is a super important part of your data plan, and helps to avoid this π kind of nonsense. If you aren't using duplicate and matching rules, you need to hop on the band wagon STAT. There's plenty of great reading out there on the best practices of setting up functional duplicate rules for your business β that's NOT what this article in about. I'm here to show you a nifty little invocable method I wrote to help manage duplicate data ... in flows!
Have you ever received this error in your flow debugs? πββοΈ
Error element Create_Contact (FlowRecordCreate).This error occurred when the flow tried to create records: DUPLICATES_DETECTED: Use one of these records?
One of your Users just tried to create a duplicate record (boo), but was stopped by your brilliantly designed duplicate rules (yay!). But in doing so, your beautiful flow came crashing to an end (boo!). You might work around this by adding a GET to find potential dupes; if any are found, don't CREATE. That can get messy, especially if you have to check multiple objects (I'm looking at you Leads and Contacts). π
Those of us brave admins who have ventured down this path know that this only leads to heartbreak. A multitude of exceptions are going to squeak by, and don't get us started on if the duplicate rules change down the road (which they will). Can't we just ask Salesforce, "Hey, I've got this Contact that I haven't created yet, does it already exist?" Why yes, yes we can!
Don't be overwhelmed β it's easy to use! Just pass in a record variable (or even just a recordId) and the code will spit out whether or not there is a duplicate record according to the duplicate rule configuration! If a duplicate record exists, then it will also give you the duplicate's recordId.
Let's say you already have this Lead.
You created an awesome screen flow to help Users enter Contacts quicker. One of your Users inadvertently tries to add Ryan Mercer the Wizard again (as a Contact). Watch what happens.
If NO, Create Contact.
If YES:
GET either the Lead or Contact using {!varDuplicateRecordId}.
And then go to town!
We hope you find this tutorial useful. Find all of the resources you need to implement this solution for yourself on this Unofficial Salesforce page!