There are several ways to avoid/restrict creation of duplicate contacts as contact roles on opportunity using APEX triggers. I am trying to build one using the 'Before Create/Update' lightning flow
- I created a checkbox field on the OpportunityContact Role object called: Duplicate Assertion
- I created a Validation Rule that checks if: Duplicate Assertion it TRUE - and prevents the save.
Get all records from OpportuniyContactRoles where OpportunityID equals $record.opportunityID
loop all records, if $record.contactid equals any returned entry
set the $record.DuplicateAssertion field to true
The save of the newly/updarted OCR's should fail if DuplicateAssertion is TRUE.
The issue is that it's not working. If I only test the assignment within the flow (as a test) - the records are correctly not saved. But if I let the process work, it saves even with a duplicate.