Mailchimp to Salesforce Integration - Part 4 [ARCHIVED - See New Article]

We have learned a lot implementing Mailchimp over the past couple of years and have updated all of our articles. Check out our new Mailchimp How To section for more ways to extend the integration.

Business Problem - Campaign Member Deletion Automation

Mailchimp - Logo

MailChimp is a great tool for people who are just starting out with email marketing and they currently use Salesforce as their CRM. We have done several implementations of MailChimp and Salesforce and wanted to provide you with our best practice approach of how to set it up right the first time.

This is Part 4 of how to setup the MailChimp to Salesforce integration where we will show you how to solve the following business challenge we ran into with implementing MailChimp for Salesforce. Check out MailChimp to Salesforce Integration - Part 1 and MailChimp to Salesforce Integration - Part 2 for additional tips.

  • Delete Campaign Member from Salesforce Campaign Automation - When a MailChimp subscriber unsubscribes from an audience, we want to delete the campaign member from a Campaign in Salesforce.

How to Instructions

Delete Campaign Member from Salesforce Campaign

Our objective here is to automatically delete the Campaign Member from a Salesforce Campaign when a MailChimp Subscriber unsubscribes from an audience in MailChimp. If you completed the steps in MailChimp to Salesforce Integration - Part 2 you already have the process builder in place that we will build off of for this automation. If you have not, please review this how to and setup the process builder with the 1st set of criteria for MC Member Status = Unsubscribed.

  • First step is to create an Autolaunched Flow, go to Setup | Flows | New Flow | Autolaunched Flow  Here is what the final flow will look like. We will go through each element in detail so you can set this up yourself.

  • Next create two text variables, to create a text variable go to the Manager tab in the Toolbox | Click New Resource button. Create two variables called varEmailAddress and varMCSubscriberId. Later you will see how we pass the values for these variables from the process builder to the flow.

  • Next we need to create two Get Records elements, one for Contacts and the other for Campaign Members. Go to the Elements tab | Drag Get Records Element onto the canvas.

    1. Get Contacts - this element is looking for all of the Contacts that have a matching MC Subscriber Id. Remember, you could have more than one Contact in Salesforce with the same email address, so there is a one to many relationship between an MC Subscriber Id and a Contact. Multiple contacts can have the same MC Subscriber Id. The Get Contacts element needs to look for All Records, not just the first record.
    2. Get Campaign Members - this element is looking for all of the Campaign Members with the MC Subscriber email address. For the same reason as above, this element also needs to look for All Records, not just the first record.

  • Now drag a Loop element onto the canvas. We need to loop through the Contact records found in the Get Contacts element so we can add them to a list to use later in the flow.

  • Create a new text collection variable called varContactIdList - make sure to click the checkbox Allow multiple values (collection)
  • Drag an Assignment element onto the canvas. Configure it like this: {!varContactIdList} Add {!Loop_Contacts.Id} This will add the current Loop variable Id to the varContactIdList variable you created.

  • Drag another Loop element onto the canvas to loop over Get Campaign Members. Since we have a many to many relationship between Contacts and Campaign Members, we need to use two Loops. You can see we made sure to do the get records queries outside of our loops. It is best practice to keep all queries and updates outside of your loops when configuring flows.

  • Next, we need to create a Custom Label to store the values of the Campaign Ids we want to use in the flow. This allows us to update the Campaign Id values without having to go into the process builder to make the change. Go to Setup | Custom Label | Click New Custom Label

    • Enter the values of the Campaign Ids into the Value field.

  • Drag a Decision element onto the canvas. Configure the Yes path like this:

    • {!varContactIdList} contains {!Loop_Campaign_Members.ContactId}.
    • {!$Label.MCSubscriberCampaignDelete} contains {!Loop_Campaign_Members.CampaignId}

  • This will check if the varContactIdList contains the value of the current Loop variable's Campaign Member Id. We updated the Default Outcome to be called No.

  • Create a new Record Variable called varCampaignMemberRecord. This variable will store the Id of the Campaign Member record so we can add them to a collection. Make sure Data Type = Record.
  • Drag an Assignment element onto the canvas. Configure it like this: {!varCampaignMemberRecord.Id} = {!Loop_Campaign_Members.Id}  This is assigning the Campaign Member Id of the current record in the loop to the Campaign Member Id in the new record variable you created.

  • Create a Record Collection variable called CollectCampaignMemberstoDelete - make sure Data Type = Record and the Allow multiple values (collection) checkbox is checked.
  • Drag another Assignment variable onto the canvas. Configure it like this: {!CollectCampaignMembersToDelete} Add {!varCampaignMemberRecord} This will add the Campaign Member records to a collection so we can delete them.

  • Now make sure to connect the arrows correctly for the Decision element. The No path should go back to the Loop Campaign Members element. The Yes path should go to the Assign Campaign Member Id element.


  • Drag a Delete Records element onto the canvas. Select Records to Delete = CollectCampaignMemberstoDelete collection variable.

  • Now is a good time to test the flow before we configure the process builder to make sure the flow works. Here are the steps I used to test it:

    • Create two contact records with the same email address in Salesforce. Make sure the email address for these contacts is also a MailChimp Subscriber
    • Create a Salesforce Campaign and add these two contacts to the Campaign.
    • Find the MC Subscriber Id of your Contacts by using the Developer Console. You may have a better way to do this, let me know!

      1. Click the Query Editor in the Developer Console
      2. Enter this query Select Id, MC4SF__Email2__c from MC4SF__MC_Subscriber__c where MC4SF__Email2__c = 'youremailaddresshere'
      3. The Id of the MC Subscriber is shown in the Query results. You should only get one record.

    • Make sure your Custom Label has the Campaign Id in the value field.
    • Click the Debug on Canvas button in the flow. Enter the two input variables: Email Address and MC Subscriber ID. Click Run.
    • Confirm the test followed the correct paths in the flow. Check the Campaign to make sure the records were deleted.
    • If everything worked, click Activate - we are ready to configure the process builder!

  • Now, go to the Process Builder you created from Part 2 of this how to series. Go to the 1st criteria that is looking for the Member Status of the MC Subscriber record to change to Unsubscribed.
  • Click Add Action and select Flows
  • Select the MC Subscriber | Delete Campaign Member flow we created above.

  • Configure the variables like this:

    • varMCSubscriberID field reference [MC4SF__MC_Subscriber__c].Id
    • varEmailAddress field reference [MC4SF__MC_Subscriber__c].MC4SF__Email2__c

  • Click Activate - we are ready to test it!

How to Test the Process Builder Invoking the Flow

  • Create two contact records with the same email address in Salesforce. Make sure the email address for these contacts is also an active MailChimp Subscriber.
  • Create a Salesforce Campaign and add these two contacts to the Campaign.
  • Add the Campaign Id to the Custom Label
  • Confirm the Process Builder and Flow are both Active
  • Go to one of the Contact pages and click Unsubscribe from the MailChimp subscriptions section.
  • Check your campaign and confirm the Contacts were deleted from the Campaign. If they are gone, congratulations!! Now you are ready to let it rip with the entire audience!

For any questions, comments, concerns – let us know in the comment section below!
We would love to hear from you!

Share This Story, Choose Your Platform!

About the Author

Cheryl Fernandes

Cheryl is a certified Salesforce Application Architect and is the Founder and Lead Salesforce Consultant at Blu Ninjas. She has been working with Salesforce for 12 years and has helped companies in financial services, insurance and beauty industries implement solutions on the platform. Flow is her favorite Salesforce declarative tool, it is a game changer for anyone who does not know how to code.

12 thoughts on “Mailchimp to Salesforce Integration – Part 4 – ARCHIVED – See New Article”

  1. Hi Cheryl,

    I am reading your mailchimp posts with great interest. My setup is quite similar but I am continuously syncing all my contacts over to the mailchimp audience and not only a specific query based on campaign membership as you mentioned in the previous post. So, I am wondering if you also have a solution to update the campaign membership status based on subscriber actions in mailchimp? I would like to set the campaign member status to “Opened” as soon as the subscriber opend the mail in mailchimp. This activity can be tracked via the Subscriber Activity Object in Salesforce but I am not sure about the flow setup to use.

    Best regards from Germany 🙂

  2. Cheryl,

    Thank you soo much for the 4 Mailchimp blogs! Followed them and now our Mailchimp integration is much more complete!


    Adam Leese

  3. Thanks Cheryl,
    Do you have any insight on how to get the campaign stats / mailchimp subscriber activity to show up on the contact record? I built a process builder for this and it is not pulling through.
    In your experience would it be better to only have 1 campaign for each newsletter or use parent campaigns?

    1. Hi Richelle,

      On your first question about campaign stats, this information should be held on the Campaign Member record or on the MailChimp subscriber activity only. There is a one to many relationship between a Contact and campaigns so the stats would be different for each campaign they are a part of. Now if you are looking to update a specific field on the Contact based on subscriber activity, then the process builder should allow you to do this – see Part 2 of this blog series. It shows you how to update the Lead or Contact from the MailChimp Subscriber record.
      On your question about is it better to have 1 campaign for each newsletter – the answer is yes. I would recommend setting up a different campaign for each newsletter so you can track them independently of one another. You can use a Parent Campaign to join all of the child newsletter campaigns together. I also recommend setting up new campaigns every year, it makes it easier when reporting on year over year results. Hope this helps.

  4. Hi Cheryl, After I create the custom label, and try to add to flow in Decision element as instructed. The label mcSubscriberCampaignDelete is not available. Is there a category or item I am missing. I’ve found bug comments but they say it was fixed in Winter 21.

    1. Hi Greg,

      I found the known issue here that I think you are referring to:

      What version is your flow? You will need to upgrade it to version 53, if you want to take advantage of the bug fix from Winter ’21. It says as a workaround, you could try renaming the custom label with a lowercase letter instead of an uppercase one. But upgrading your flow version is best. Let me know if this works for you.

  5. Vicky McLaren

    Hi Cheryl
    Thank you so much for these in depth guides! They are making my life so much easier!
    I have two questions about this solution:
    1. I’m working with a Mailchimp account that has multiple audiences – combining into one is not an option. How can I adapt this solution to be audience specific?
    2. How could we make this solution look after itself? I can see an admin must add the campaign IDs to a custom label to make sure they are included in the delete?

    I’d be really interested to learn more on these issues.


    1. Hi Vicky,

      Thank you for your questions. We are in the process of updating the MailChimp automations to use only flow. When we get to this one, we will think about how we can address these questions and give you our best recommendation. I like where you are going with #2, this would be ideal.

    2. Hi Vicky,

      I wanted to update you on some enhancements we have made to our articles based on your questions.

      Question #2: We have a new article: that shows you how to better handle this business problem. No more custom labels! You can manage this now from a checkbox on the Campaign record. It is a much simpler solution.

      Now, if you have multiple audiences, this is a little more involved because the same person could be in two different audiences. If you have the campaign members in audience specific campaigns, this would help you solve the issue.

      Let me know if this helps you.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top