Create Custom Campaign Statuses from a Template Automagically

Kevin Zeigler
Mission: Impactful
Published in
8 min readJan 7, 2022

If you’ve used the Campaign object before for events or fundraising efforts, you’ll know that there are two possible statuses that are applied to Campaign Members: Sent and Responded. Updating these requires that you add new statuses to the Campaign Member Statuses related list for each campaign.

THE ASK: Can we automatically create custom Campaign Member Statuses with no code?

ANSWER: Yes! Flows are awesome.

In this edition of Solutions Engineered, I’ll show you one way to approach this problem using flows. Never used flows before? No problem, I’m going to walk you through this step by step. Grab some coffee, fire up your sandbox or dev org (you’re not doing this in production, RIGHT?!), and let’s get going.

Step 1: Create two Custom Objects

Create two custom objects to hold your custom Campaign Member Status template and the statuses in each template. I called these Campaign Status Template and Campaign Status Template Item, but you can call them whatever you like. Add the following fields at a minimum:

Campaign Status Template

Campaign Status Item

Step 2: Add a Lookup on the Campaign Object

We will add a new lookup field on the Campaign object to let us select the template that Salesforce should use to populate the Campaign Member Status records for a newly created campaign. The lookup should point to the Campaign Status Template object that we created in Step 1.

Step 3: Create a Flow

Now the fun begins, it’s time to create your flow. In a nutshell, the Flow is going to:

  • Receive the Campaign Id from the newly created campaign
  • Grab your custom Campaign Status Items from the template you selected in the lookup field
  • Create new custom Campaign Member Status records from those custom statuses
  • Delete the default Campaign Member Status records (Sent and Responded).

First, create a new record triggered flow. You can use the Freeform Layout option for this when asked on the next screen. Next, select which object the flow will trigger from and enter the parameters for when this flow should execute. Add a Get Records element to your Flow and follow the instructions and screenshot below.

Object: Campaign
Trigger the Flow When: A record is created
Set the Entry Criteria:

Optimize the Flow for: Actions and Related Records

Next we need to get the existing Campaign Member Status records that Salesforce automatically creates when you create a new campaign. We’ll want to delete these later so that only our custom statuses remain. Add a Get Records element by dragging it onto the flow canvas. Follow the instructions and screenshots below for the parameters.

Label: Get Existing Campaign Member Status Records
Object: Campaign Member Status
Filter: CampaignId = {!$Record.Id}
How Many Records to Store: All records
How to Store Record Data: Automatically store all fields

Once we have the existing Campaign Member Status records, we need to grab our custom campaign statuses. This one will find all of the custom statuses that are a part of the template you selected when you created the campaign. Add another Get Records element to your Flow and follow the instructions and screenshots below for the parameters.

Label: Get Custom Campaign Member Status Records
Object: Campaign Status Item
Filter: Campaign_Status_Template__c = {!$Record.Campaign_Status_Template__c}
How Many Records to Store: All records
How to Store Record Data: Automatically store all fields

Step 4: Loop through the Custom Campaign Member Status Records

Now that we have all of our custom statuses in a “bucket” (a collection variable), we will loop through them and stage them to create records in the CampaignMemberStatus object. This involves a few elements: a Loop element and an Assignment element.

Add a Loop element to your flow. Here, we are telling Salesforce “take those custom status records you just grabbed for me and cycle through them one by one and let’s do something with them”.

Label: Loop Custom Status Records
Collection Variable: {!Get_Custom_Campaign_Member_Status_Records}

OK, so now we’re loopin’. Let’s tell Salesforce what to do with each iteration of our loop. Add an Assignment element to your Flow. We need to ‘transform’ the records from our custom Campaign Status Item object into a record for the standard CampaignMemberStatus object. To do this, we’ll need to create a record variable for us to put our values in temporarily. Click New Resource under the Manager tab and follow the instructions and screenshot below.

Resource Type: Variable
API Name: New_Custom_CampaignMemberStatus
Data Type: Record
Object: Campaign Member Status

Now let’s transform our custom status to something we can use to create the CampaignMemberStatus records that our newly created campaign record can use. Add an Assignment element to your flow and follow the instructions and screenshot below.

Label: Convert to CampaignMemberStatus Record
Set Variable Values:

Excellent, we’re almost there. Now that we’ve transformed our record, we just need to toss it into the “here’s all the stuff for you to create, Salesforce” bucket. We’ll do that with one more Assignment element. Just like before, we need to create this bucket first. Click New Resource under the Manager tab and follow the instructions and screenshot below.

Resource Type: Variable
API Name: CampaignMemberStatus_to_Create
Data Type: Record Make sure that Allow multiple values (collection) is checked!
Object: Campaign Member Status

OK, let’s toss that newly transformed record into our new bucket, CampaignMemberStatus_to_Create. This time, we are simply going to say “take that record, and add it to my collection variable”. Add another Assignment element to your flow and follow the instructions and screenshot below.

Label: Add to CampaignMemberStatus Collection
Set Variable Values:

Step 5: Create the New Statuses for your Campaign

We are almost at the finish line. Now we need to create all the new CampaignMemberStatus records from our bucket, CampaignMemberStatus_to_Create. To do this, add a Create Records element to your flow and follow the instructions and screenshot below.

Label: Create CampaignMemberStatus Records
How Many Records to Create: Multiple
Record Collection: {!CampaignMemberStatus_to_Create}

Step 6: Delete the Default Campaign Member Status Records

Remember how our first step was grabbing the default CampaignMemberStatus records? Well now we are going to tell Salesforce to get rid of em’. We have shiny new CampaignMemberStatus records from our template. Add a Delete Records element to your flow and follow the instructions and screenshot below.

Label: Delete Default CampaignMemberStatus Records
How to Find Records to Delete: Use the IDs stored in a record variable or record collection variable
Record or Collection Variable: {!Get_Existing_Campaign_Member_Status_Records}

Step 7: Connect All of Your Elements

Make sure that all of your elements are connected in the proper order. Use the screenshot below for reference. This pattern of grabbing some records, looping through them and performing some action, and creating/updating records is very common with flows. You can reuse this pattern for lots of different use cases!

Save your Flow and give it a name. I called mine Create Custom CampaignMemberStatus Records. Don’t forget to Activate your flow!

Step 8: Test!

To test our flow, we need an example template and some example statuses to include. I’m creating a template record called Fundraising Event with several statuses:

  • Invitation Sent
  • Accepted Invitation
  • Declined Invitation

Now let’s create a new campaign record, tell Salesforce to use our new template and see what happens! I’m going to create a new campaign for an upcoming Winter Fundraising Event. Be sure to select your newly created template in the lookup field for Campaign Status Template.

EXCELLENT! Congratulations, you’ve built a pretty cool flow here 😎.

A few last points to note…

You’ll notice we didn’t use the Debug functionality in Flow. This is an awesome tool to help you troubleshoot problematic flows. Check out more here.

You could also add some simple tweaks to improve this functionality. For example, you could use the Active checkbox we added (and didn’t use in this tutorial) on the Campaign Status Template object that you could use as a lookup filter to give users only active templates to choose from.

I hope you were able to follow along and find this flow useful! Check below for some helpful links.

Helpful Links and Information:
Salesforce Documentation: Create a Custom Object
Salesforce Documentation: Flow Debug
Salesforce Documentation: Flows
Trailhead: Create a Custom Object
Trailhead: Build Flows with Flow Builder

NOTE: Please note that the information in this blog post is not intended to be Salesforce implementation advice. As a Solution Engineer, I build solution demos that highlight what you can do with Salesforce, not necessarily what you should do in your production environment. You should always solicit the advice of an experienced, certified Salesforce partner when making implementation decisions.

--

--