I recently ran into a situation where a client needed to exclude select campaign types from being populated as the Primary Campaign Source field on opportunities. While this might sound unusual on the surface, the use case was very logical and likely impacts other organizations too. Read on to learn how we solved it to customize primary sources on opportunities using Salesforce flow.

Use Case

Before getting too deep into the solution, let’s first review the use case for relevancy in your organization. In this particular situation, the sales teams were leveraging Salesforce campaigns as a way to group records for outreach. Some of the outreach campaigns became quite large over time and began skewing data in the Primary Campaign Source field on opportunities.

Many reports in the organization were based on the Primary Campaign Source field and the outreach campaigns were undermining the impact of true marketing campaigns. It was determined that reporting would be more accurate if outreach campaigns were excluded and the Primary Campaign Source field was populated using the last “responded” campaign (based on the responded checkbox).

Primary Campaign Source Field Review

Before we get into the solution, let’s do a quick recap of the Primary Campaign Source field on opportunities. Campaign attribution can be a confusing topic, so it never hurts to review.

How is the Primary Campaign Source Populated?

Lead Conversion (with Opportunity) – The Primary Campaign Source field will be populated with the campaign that was most recently associated with the lead.

Opportunity Creation (from Contact) – The campaign that the contact was most recently associated with will populate the Primary Campaign Source field when a new opportunity is being created from a contact record. Users have the ability to change the value before saving the record. 

Manually – Users can manually update the Primary Campaign Source field on the opportunity using the picklist of active campaigns.

Automation – The Primary Campaign Source field can also be updated based on an automated process in Salesforce (generally a Flow).

Do Auto-Association Rules Apply?

Great question! Auto-association rules are part of campaign influence in Salesforce and are used to create campaign influence records. They are not factored into the population of the Primary Campaign Source field on opportunities.

Primary Campaign Source Field (on Opportunities) vs. Primary Source Campaign Influence Model

Primary Campaign Source Field (on Opportunities) – Lookup field on the opportunity that links it to a single campaign.

Primary Source Campaign Influence Model – Campaign influence model that attributes 100% of the influence to the campaign noted in the Primary Campaign Source field on an opportunity.  

Solution Review

Now that we’ve laid the foundation, let’s address the solution.

Step 1 – Determine Exclusions & Actions

The first question to answer is “What campaigns should be excluded from the Primary Campaign Source field?”. Depending on your organization, this could be a campaign type, a campaign record type, or a combination of both. 

Step 2 – Determine Actions

Now that we know what campaigns we would like to exclude, what should we do when we run across an opportunity with an excluded value? The default Salesforce behavior is to use the last associated campaign. We could go that route and use the last “valid” campaign that a lead or contact was associated with or we could go a step further and use the last campaign that has the “responded” box checked.

I prefer prioritizing my “valid” campaigns based on the “responded” checkbox. Similar to how I configure auto-association rules, I just don’t like giving credit to a campaign if the lead/contact has not actually engaged with it.

We also need to consider how the Primary Campaign Source will be populated if no valid campaigns are found. You can choose to keep the excluded value (as a reference point), clear the value, or populate with a default value. I elected to retain the excluded value (prefer data to no data), but you have options!

Step 3 – Build it in Flow (Sandbox)

For illustrative purposes, I created a flow in my dev org to show you how this solution could work for you. Here are the assumptions that were used.

Campaigns with the type of “Sales Prospecting” should be excluded.

When updating the Primary Campaign Source field, the most recent responded campaign (checkbox checked) should be used.

If a valid campaign is not found (or the only campaign has a non-responded member status), the Primary Campaign Source field should be populated with the most recent campaign (basically defer to the default Salesforce behavior).

Since this data is used for reporting purposes, real-time updates are not needed. 

Flow Summary 

This solution uses a scheduled flow based on the opportunity object. The flow runs nightly and processes all opportunities that were created or updated that day.

Note: Relative dates can’t be used in the filter conditions of scheduled flows. To address this, create a custom checkbox field on the opportunity object that will evaluate TRUE if the opportunity was created or updated today and use it in your criteria.

Below is my filter. It’s selecting opportunities that have contact roles and were created or updated today.

Get campaign members for contact roles

In this step, we get all the responded campaign member records (for the contact role) and sort them so the most recent is first.

Loop through campaign members

Next, we loop through each of the campaign member records related to the contact role, find the first valid campaign (responded), and save it to the assignment variable.

Update the opportunity record

Finally, we update the Primary Campaign Source field on the opportunity with the campaign ID stored in the assignment variable.

Note: If you decide to keep the most recent campaign as the Primary Campaign Source (if a valid campaign is not found), you will need to add a final assignment element prior to updating the record. The element uses a formula to ensure that the variable has been populated with a valid value and updates to the original campaign ID (even if it’s an excluded value) if blank. This prevents the Primary Campaign Source from being updated to a null value by the flow.

Complete Flow 

Here’s a look at my final flow.

Step 4 – Test & Validate

As with any flow, test, test, and test again before deploying to production. Below are some test scenarios to use for validation.

Create a new opportunity at lead conversion 

Lead with a single valid campaign

Lead with multiple valid campaigns 

Lead with an excluded campaign (most recent) and a valid campaign 

Lead with a single excluded campaign 

Lead with a single non-responded campaign membership

Create a new opportunity from a contact 

Contact with a single valid campaign 

Contact with multiple valid campaigns 

Contact with an excluded campaign (most recent) and a valid campaign 

Contact with a single excluded campaign

Contact with a single non-responded campaign membership

Update Primary Campaign Source on an existing opportunity

Update to an excluded value (make sure that there’s a contact role who has a valid campaign) 

Test Table

When testing and validating flows, I like creating tables to record results for review. This helps me organize my thoughts and ensure that everything is working as intended.

ScenarioCurrent ValueExpected ValuePass/FailLead – Single Valid2023-09 TSW Dreamforce2023-09 TSW DreamforcePASSLead – Multiple Valid2024-06 SLS Sales Prospecting2023-06 WBR Product Update WebinarPASSLead – Excluded + Valid2024-06 SLS Sales Prospecting2023-09 TSW DreamforcePASSLead – Single Excluded2024-06 SLS Sales Prospecting2024-06 SLS Sales ProspectingPASSLead – Single Non-Responded2023-09 TSW Dreamforce2023-09 TSW DreamforcePASSContact – Single Valid2024-05 TSW Events2024-05 TSW EventsPASSContact – Multiple Valid2023-06 WBR Product Update Webinar2023-06 WBR Product Update WebinarPASSContact – Excluded + Valid2024-06 SLS Sales Prospecting2023-09 TSW DreamforcePASSContact – Single Excluded2024-06 SLS Sales Prospecting2024-06 SLS Sales ProspectingPASSContact – Single Non-Responded2023-09 TSW Dreamforce2023-09 TSW DreamforcePASSUpdated  – Existing Updated to Excluded2024-06 SLS Sales Prospecting2023-09 TSW DreamforcePASS

Is the Primary Campaign Source field meeting your needs?

If you are using the Primary Campaign Source field in your reporting I encourage you to take a closer look at your campaigns to see if your data is being skewed. If so, this solution is a great way to prioritize valid campaigns and put more emphasis on engagement. You can even completely filter out specific types of campaigns if you choose. Don’t sell your marketing efforts short!

More Salesforce Flow resources

An Introductory Guide to Salesforce Flow for Marketers

Getting Started with Einstein for Flow

How to Update Marketing Personas Using Salesforce Flow

Creating Custom Object Records with Account Engagement and Flow

Salesforce Automation Game-Changer: Einstein GPT and Data Cloud Capabilities for Flow

Original article: How to Customize Primary Source on Opportunities with Salesforce Flow

©2024 The Spot. All Rights Reserved.

The post How to Customize Primary Source on Opportunities with Salesforce Flow appeared first on The Spot.

By