Preventing duplicate junction object records
Native dupe management only allows you to reference a single lookup field. So it cannot prevent duplicate junction object records.
By using a (new in spring 20) before save flow to concatenate the two IDs into a single text field, you can prevent duplicate junction object records.
This cannot be done with workflow rules, because of the order of operations. Dupe rules are evaluated at step 6, and workflow at step 11 (as of Feb 2020)
Here are the steps
- create a text field named Compound Key on your junction object
- create a flow
- click on the start button and set the flow to launch on ‘new or updated records’ (you can decide if it fires on insert, update, or both)
- add an assignment element that sets Compound Key to a formula field which concatenates the two ID fields on the record
- create and activate a matching rule that matches on Compound Key (exact)
- create and activate a dupe rule that alerts / blocks - whatever makes sense in your case
Moredetails and screenshots below
step 3 : after clicking on start button
step 4: the assignment element
step 4: the formula field to concatenate the IDs
you may be able to do this directly in the assignment element - did not test that
thats about it - just activate and watch the magic happen!
the main downside to this proof of concept is that the field that is displayed in the alert is the compound key field…which is less than ideal. so instead of using compound key, you could match on one lookup using the dupe rule, and use this flow approach to set a single ID to match against. then you only have one ugly ID show. You can’t do any cross object stuff in the flow, so you only have access to the related records IDs, so options are somewhat limited - but maybe you can figure something out.
UPDATE: JUNE 2022:
h/t to Cassie Supilowski for sharing that in LEX the duplicate error message comes through beautifully - her screenshots are copied below.