This guide walks through building a Record-Triggered Flow in Salesforce that automatically adds a newly created Lead to a specific Campaign when that Lead arrives from a particular Lead Source. It's useful any time you want inbound leads from a given source — an event, a partner, a data provider, a web form — routed into a targeted campaign the moment they're created, with no manual list-building.
Throughout this guide, replace the example values with your own: this example enrolls leads with a Lead Source of "FanCompass" into a campaign named "FanCompass | Evergreen." Substitute your real Lead Source value and Campaign name wherever you see them.
Flow Type: Record-Triggered Flow Status: Inactive (requires manual activation after setup)
Before You Begin
- Permissions: You need access to build flows (the Manage Flows permission, typically a System Administrator).
- The Campaign must already exist. This flow finds a campaign by its exact Name — it does not create one. Create your target campaign first and note its exact name.
- Know your exact Lead Source value, including capitalization and spacing. If it's a custom value that isn't in the standard Lead Source picklist, open a real lead that has it and confirm the exact stored string.
- Decide your trigger timing. This guide fires when a lead is created. If you also want existing leads to qualify when they're later updated to that source, see Adapting This Flow for Your Org.
Table of Contents
- Before You Begin
- Flow Logic Summary
- Step 1: Create the Flow
- Step 2: Configure the Start Element (Trigger & Entry Conditions)
- Step 3: Add a Get Records Element – "Get Campaign"
- Step 4: Add a Create Records Element – "Add to Campaign"
- Step 5: Add End Elements
- Step 6: Save, Test, and Activate
- Resource Summary Table
- Notes on Auto-generated variables
- Adapting This Flow for Your Org
- Troubleshooting
- Screenshots
Flow Logic Summary
The flow runs automatically whenever a new Lead is created. An entry condition on the Start element limits it to Leads whose Lead Source matches the value you specify (in this example, "FanCompass"). For each qualifying Lead, the flow looks up your target Campaign by name, then creates a Campaign Member record linking that Lead to the Campaign. Execution is a single linear path with no branches: Start → Get Campaign → Add to Campaign → End. Leads with any other Lead Source don't meet the entry condition, so the flow doesn't run for them.
Step 1: Create the Flow
- Go to Setup → Process Automation → Flows and click New Flow.
- Select Record-Triggered Flow and click Create.
- Click the flow title and give it a clear, descriptive name. Example: "Add FanCompass Leads to Campaign." The API Name auto-populates.
- Add a Description so future admins understand its purpose. Example: "Adds a newly created Lead with Lead Source = FanCompass to the 'FanCompass | Evergreen' Campaign as a Campaign Member."
Step 2: Configure the Start Element (Trigger & Entry Conditions)
Click the Start element and set:
- Object: Lead
- Trigger the Flow When: A record is created
- Optimize the Flow for: Actions and Related Records. Why: this flow creates a related record (a Campaign Member) after the Lead is saved, so it must run in the "after-save" context — this option provides that.
Set Entry Conditions (so the flow only runs for the leads you care about):
- Condition Requirements: All Conditions Are Met (AND)
- Condition: Lead Source | Equals | [your Lead Source value — this example uses FanCompass]
- Condition: Email isNull | Equals | False
Note: The match must be exact. If your value isn't one of the standard Lead Source picklist values (Web, Phone Inquiry, Partner Referral, Purchased List, Other), you can still type it as a literal text value — but it must match what's stored on the lead exactly, including capitalization and spacing, or the flow won't fire.
Step 3: Add a Get Records Element – "Get Campaign"
After the Start element, add a Get Records element.
- Label: Get Campaign (API Name: Get_Campaign)
- Object: Campaign
Filter Campaign Records:
- Condition Requirements: All Conditions Are Met (AND)
- Condition — Field: Name, Operator: Equals, Value: FanCompass | Evergreen (your Campaign name)
Sort Campaign Records: Not Sorted
How Many Records to Store: Only the first record
How to Store Record Data: Automatically store all fields
Note: The lookup is by exact campaign Name, and the name here contains spaces and a pipe character ("FanCompass | Evergreen"), so it must match the campaign record exactly — including the spaces around the "|". Make sure exactly one active campaign uses that name. If several campaigns could share a similar name, tighten the filter (for example, add IsActive Equals True) or sort so the intended one is returned first — otherwise the flow may pick the wrong campaign or none at all.
Step 4: Add a Create Records Element – "Add to Campaign"
After Get Campaign, add a Create Records element. Why: a Campaign Member is the junction record that links a Lead (or Contact) to a Campaign, so creating one is what actually enrolls the lead.
- Label: Add to Campaign (API Name: Add_to_Campaign)
- How to set record field values: Manually
- Object: Campaign Member
Set Field Values for the Campaign Member:
| Field | Value |
|---|---|
| Campaign ID (CampaignId) | Campaign from Get Campaign → Campaign ID ({!Get_Campaign.Id}) |
| Lead ID (LeadId) | Triggering Lead → Lead ID ({!$Record.Id}) |
Manually assign variables (advanced): Leave unchecked — there's no need to store the new Campaign Member's ID.
Step 5: Add End Elements
Connect the output of "Add to Campaign" to an End element. This flow has a single path (Start → Get Campaign → Add to Campaign → End); leads that don't match the entry condition never start it, so no extra branch is needed.
Step 6: Save, Test, and Activate
- Click Save and confirm the version details.
- Test with Debug. Use the Debug button with "Run automation in rollback mode" checked so no real Campaign Member is committed during testing. You'll need at least one Lead — ideally one with your trigger Lead Source — to test against. Confirm the flow finds the campaign and would create the member.
- When satisfied, click Activate.
Important: Because the flow triggers on record creation, it only enrolls leads created after activation. Existing leads already in your org won't be processed (to handle those, see the next section).
Resource Summary Table
| Variable | Type | API Name | Created By | Used By | Purpose |
|---|---|---|---|---|---|
| Campaign from Get Campaign | Record (Single) Variable | Get_Campaign | Auto-generated by Get Campaign element | Add to Campaign | Stores the retrieved Campaign record; provides the Campaign ID for the new Campaign Member |
| Campaign Member from Add to Campaign | Record (Single) Variable | Add_to_Campaign | Auto-generated by Add to Campaign element | None (available for downstream use) | Holds the reference/ID of the Campaign Member record created by the Add to Campaign element |
Notes on Auto-generated variables
A. Record (Single) Variable — Campaign from Get Campaign (API Name: Get_Campaign)
Purpose: Stores the single Campaign record retrieved by the Get Campaign element. It holds all of the Campaign's field values — including its Campaign ID — so they can be referenced later. Specifically, the Campaign ID is passed into Add to Campaign to associate the lead with the correct campaign.
Important note: This variable is generated automatically when you configure a Get Records element to store "only the first record" and automatically store all fields. You don't create it separately.
B. Record (Single) Variable — Campaign Member from Add to Campaign (API Name: Add_to_Campaign)
Purpose: Represents the Campaign Member junction record created by Add to Campaign, linking the Lead to the Campaign. Salesforce generates this reference automatically when the Create Records element runs.
Important note: Because "Manually assign variables (advanced)" is left unchecked, no separate manual ID variable is created — the auto-generated reference is sufficient.
Adapting This Flow for Your Org
- Trigger on a different field. The entry condition can use any Lead field — a campaign code, country, product interest, etc. Just change the field, operator, and value in Step 2.
- Include existing leads, not just new ones. Set Trigger the Flow When to "A record is created or updated," and consider the option to run only when the condition is newly met, so leads aren't re-processed on every edit.
- Use Contacts instead of Leads. Build the same pattern on the Contact object and map Contact ID instead of Lead ID on the Campaign Member.
- Route multiple sources to different campaigns. Add a Decision element after Start to branch by Lead Source, with a separate Get Campaign / Add to Campaign per branch.
- Avoid duplicate members. A Lead can only be a member of a given Campaign once. In a create-only flow this isn't a concern, but if you switch to "created or updated," add a Get Records check (or a fault path) so an already-enrolled lead doesn't cause an error.
Troubleshooting
- The flow never runs. Confirm the flow is Active, the trigger is correct (created-only won't fire for existing leads), and the Lead Source value on the lead matches your entry condition exactly (capitalization and spacing).
- No Campaign Member is created. Usually the campaign name doesn't match. Get Campaign finds nothing if the Name isn't an exact match (including the spaces around the "|" in "FanCompass | Evergreen") or the campaign doesn't exist — verify the name in Step 3.
- "Duplicate" or insert error. The lead is already a member of that campaign. Add a check or fault handling as described above.
- Older leads weren't added. Expected — a created-triggered flow only affects leads created after activation. Enroll existing leads with a separate scheduled flow or a one-time list import.
Screenshots
Start Element | Trigger & Entry Conditions
Get Records | Get Campaign
Create Records | Add to Campaign
Flow Canvas Overview
Comments
0 comments
Please sign in to leave a comment.