Add to campaign
Audience:
Low-code EngineersSkill Prerequisites:
Actions,Tokens,Connectors
Adds an existing Salesforce lead to one or more campaigns. The action signs in to Salesforce with a Salesforce connector and creates one campaign member record for each campaign.
The lead must already exist. The action doesn't create or look up leads, so you pass the lead's ID, for example from Create a Salesforce Entity or Run SOQL Query.
This action is part of the Salesforce add-on (DnnSharp.Salesforce). The add-on is installed separately and needs the SALESFORCE feature in your license. If it isn't licensed, the action fails with a "not licensed" error. If you don't see the Salesforce actions, the add-on isn't installed.
Typical Use Cases
- Add a lead created from a web form to a marketing campaign
- Register a lead for several campaigns at once, for example an event and a newsletter
- Save the campaign member ID so later actions can refer to it
Don't use it to
- Create the lead. Use Create a Salesforce Entity first, then pass its ID to this action.
- Find a campaign by name. The action only takes campaign IDs. Use Run SOQL Query to look up the ID first.
- Add contacts, accounts or cases. The ID is always sent as a lead ID. See Leads only.
- Set the member status, or change or remove an existing member. The action only creates new members.
Related Actions
| Action Name | Description |
|---|---|
| Create a Salesforce Entity | Creates a lead or other record and returns its ID. |
| Run SOQL Query | Looks up records, for example a campaign ID from its name or a lead ID from an email. |
| Add Salesforce Connector | Creates the Salesforce connector this action uses. |
| Update Salesforce Connector | Changes the login details of a Salesforce connector. |
| Test Connector | Checks that a connector can sign in. |
| Add to campaign (obsolete) | The older version that stores the login details in the action. |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Connector | The Salesforce connector to sign in with. See Add Salesforce Connector. When using an expression, the value must be the connector ID. | Yes | none | Yes |
| Salesforce Entity Type | A list with Lead, Case, Contact and Account. The action ignores this setting and always adds the ID as a lead. See Leads only. | No | empty string | No |
| Entity Id | The ID of the lead to add, for example [LeadId]. Both 15 and 18 character IDs work. | Yes | empty string | Yes |
| Campaign Ids | One or more campaign IDs, separated by commas, for example [EventCampaignId],[NewsletterCampaignId]. Both 15 and 18 character IDs work. Spaces around the IDs are removed. | Yes | empty string | Yes |
| Campaign Member Token Name | The name of a token to save the new campaign member ID in, for example CampaignMemberId. | No | empty string | No |
| Campaign Member URL Token Name | The name of a token to save a link to the new campaign member in. In 1.28 this value isn't a working link. See Considerations. | No | empty string | No |
| On Successful Add | Actions to run after the lead is added to a campaign. They run once for each campaign. | No | empty | No |
| On Error | Actions to run when the action fails. The [ErrorMessage] token holds the error message. | No | empty | No |
Output Parameters Reference
| Parameter | Description |
|---|---|
[<Campaign Member Token Name>] | The ID of the campaign member record Salesforce created. With several campaigns, it holds the current campaign's member while On Successful Add runs, and the last one after the action ends. |
[<Campaign Member URL Token Name>] | / followed by the campaign member ID, for example /00v000000000001AAA. |
[ErrorMessage] | The error message, set when the action fails. |
How it works
- The action signs in to Salesforce with the connector.
- It splits
Campaign Idsat the commas and turns 15 character IDs into 18 character IDs. - It checks that all campaigns exist. If any are missing, it fails with
Campaigns with the following ids does not exist: ...and adds the lead to none of them. - For each campaign, in order, it creates a campaign member for the lead, fills the output tokens and runs
On Successful Add.
If On Successful Add stops execution or returns a result, for example with a redirect, the remaining campaigns are skipped.
Leads only
The action always sends Entity Id as the campaign member's lead ID, whatever Salesforce Entity Type is set to. A contact ID or any other ID is rejected by Salesforce and the action fails.
Errors
When the action fails, [ErrorMessage] is set. If Salesforce returns several errors, they're joined with <br />.
- If
On Errorhas actions, they run and the action doesn't raise an error. - If
On Erroris empty, the action raises an error:Failed to add entity to campaign.followed by the error message. End users seeFailed to add entity to campaign.
Common errors are a wrong login in the connector, a lead ID that doesn't exist, a campaign that doesn't exist, and a lead that's already a member of the campaign.
Considerations
- No rollback. Campaigns are added one at a time. If the third campaign fails, the lead stays a member of the first two.
- Duplicates fail. If the lead is already a member of a campaign, Salesforce returns an error and the action runs
On Error. Campaigns later in the list aren't added. Check membership first with Run SOQL Query if this can happen, for exampleSELECT Id FROM CampaignMember WHERE CampaignId = '[CampaignId]' AND LeadId = '[LeadId]'. - Don't list a campaign twice. The existence check compares counts, so a repeated ID makes the action fail with the "does not exist" error.
- Member status isn't set. Salesforce gives the new member the campaign's default status.
- Empty
Campaign Ids. If the value is empty, the action fails. If it only has commas, for example,, the action logsNo campaign to register to.and ends without runningOn Successful AddorOn Error. - The URL token isn't a working link. It only contains
/and the ID. To link to the record, build the URL yourself from your Salesforce domain and[<Campaign Member Token Name>]. - Errors are logged. Each error is also written to the event log.
Examples
To understand how to use the below examples, please see Running Examples.
1. Add a new lead to a campaign
This action adds the lead in [LeadId], for example created earlier by Create a Salesforce Entity, to the campaign in [WebinarCampaignId]. The campaign member ID is saved in [CampaignMemberId]. Replace the connector ID with your Salesforce connector.
{
"Title": "Add to campaign",
"ActionType": "AddToCampaignWithCredentialStore",
"Description": "Add the new lead to the webinar campaign",
"Condition": "[LeadId] != \"\"",
"Parameters": {
"Credentials": {
"Entry": "00000000-0000-0000-0000-000000000000"
},
"sforceEntityType": "lead",
"EntityId": "[LeadId]",
"CampaignIds": "[WebinarCampaignId]",
"CampaignMemberTokenName": "CampaignMemberId"
}
}
2. Add a lead to several campaigns with error handling
This action uses the connector ID in [SalesforceConnectorId] and adds the lead to two campaigns. If anything fails, the error is written to the log.
{
"Title": "Add to campaign",
"ActionType": "AddToCampaignWithCredentialStore",
"Description": "Add the lead to the event and newsletter campaigns",
"Parameters": {
"Credentials": {
"IsExpression": true,
"Entry": "[SalesforceConnectorId]"
},
"sforceEntityType": "lead",
"EntityId": "[LeadId]",
"CampaignIds": "[EventCampaignId],[NewsletterCampaignId]",
"OnError": [
{
"Title": "Log Error",
"ActionType": "LogError",
"Parameters": {
"Message": "Salesforce campaign error for lead [LeadId]: [ErrorMessage]"
}
}
]
}
}
Revised 09/27/2026