How to avoid adding duplicate campaign members to a campaign in process builder (to avoid errors)? - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Tracey MullaneTracey Mullane 

How to avoid adding duplicate campaign members to a campaign in process builder (to avoid errors)?

I am learning how to use Process Builder and trying to create a process where when a checkbox on a contact record is checked, the contact is added to a campaign. There are seven checkboxes total (for email list signups). 

The Process is starting on the Contact object, and then I'm creating a new Campaign Member Record as the "Immediate Action."

I've been able to set up a process to add contacts to each of the campaigns, BUT, if a contact is already a member of the campaign, I get this error message: "(INSERT --- INSERT FAILED --- ERRORS : (DUPLICATE_VALUE) This entity is already a member of this campaign,"

I can't figure out what I need to do in Process Builder to tell it to ignore trying to add a contact again if they're already a member of that campaign. While I hope that the checkboxes will be in sync with their campaign membership (checked = member, not checked = not a member), I want to build the process with the possibility that contacts are already in campaigns in mind.

Do I need to be using a Flow in conjunction with Process Builder to address the possibility of the contact already being a campaign member? Or is there something I can do in the criteria or immediate actions steps (whether formula, reference, etc) that would lookup if the contact is already a campaign member and then do nothing if they are?

Many thanks!

Deepak AnandDeepak Anand
Well, that's all with the Process . We can't set it up in that way where it could detect duplicates and create records accordingly. 

To mitigate this, we will have to spawn a Flow as the Immediate Action. The Flow will do a Record Lookup to see if there is CampaignMember record already existing with the specified CampaignId and ContactId(with a Decision Element). If there exists one then don't do anything else you can do the Record Create to create a CampaignMember record.

This Flow will be executed via the Process. Also you'll need to create a Input and Ouput type Variable to receive the ContactId from the Process.
Tracey MullaneTracey Mullane
Many thanks - I think I got this working yesterday with a Flow, though more testing is needed. AT least I'm pointed in the right direction!
Hana SantHana Sant
How can I create the flow described?
Tracey MullaneTracey Mullane
Hi Lindsay - I followed the process outlined here and got it working. I haven't yet reversed-engineered it so that unchecking a box removes the contact from a campaign...