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

enter image description here

  • 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.

In my 'Before Create/Update', it's a simple flow: enter image description here

  • Get all records from OpportuniyContactRoles where OpportunityID equals $record.opportunityID

  • loop all records, if $record.contactid equals any returned entry

  • The Decision rule enter image description here

  • set the $record.DuplicateAssertion field to true

  • The Assignment enter image description here

  • 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.

Any ideas?


There is a mistake in the Loop object. The return arrow from the 'Assignment' object, needs to go to the Loop object, and not the 'Decision' object.

A way to identify this was also to use the 'Auto-Layout' feature. It mentioned the error, only I had to figure out what it meant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.