openDistributedMarketing(config)

Launches the Distributed Marketing modal, containing the audience, campaign, or flow that you supply. The method opens the multi-step Distributed Marketing wizard, which includes these steps shown in order of appearance:

  • Campaign
  • Audience
  • Personalize
  • Preview & Send

The lightning/distributedMarketing module re-exports the static method on the internal DiscoModal component.

Syntax 

1import { openDistributedMarketing } from 'lightning/distributedMarketing';
2openDistributedMarketing(config: DmLauncherConfig): void

The method opens the modal and returns void. It throws a DiscoError synchronously if the configuration fails validation. See Error Handling.

Parameters 

The method accepts a single config object of type DmLauncherConfig with these parameters.

ParameterTypeRequiredDescription
audiencestring[]YesA non-empty array of Salesforce record IDs that seeds the Distributed Marketing audience. Each ID must be a valid 15- or 18-character ID for a Contact, Lead, Prospect, or CampaignMember. You can mix types within the array as long as each ID resolves to one of these sObjects.
campaignIdstringNoA valid Campaign ID. When provided, the Campaign Picker is pre-filtered to this campaign, which saves the user from searching for it. Required when flowId is provided.
flowIdstringNoA valid flow definition ID. When provided, the modal fetches the flow directly and bypasses campaign and flow discovery in the Campaign Picker. You must provide campaignId with flowId. Passing flowId without campaignId throws an error. Use flowId when the specified campaign has multiple flows. If you don’t pass a flowId, the modal doesn’t auto-select a flow, and the user picks one manually.
skipAudienceSelectionbooleanNoWhen true, the Audience Picker step is skipped and the modal uses the supplied audience as-is. Because the audience can’t be edited in the modal when this option is set, audience must be non-empty. Defaults to false.
actionableListIdstringNoA valid actionable list Id. When provided, the modal sends to the whole list. List must be under the max list size, currently 2000.
defaultContentstringNoOmitted or ‘LastSent’ (default): Load the last published content for the selected template. ‘None’: start from the base template

Validation Rules 

The method enforces these rules synchronously, before the modal opens.

  • The config object must be provided.
  • audience must be an array with at least one element.
  • Every audience ID must be a syntactically valid Salesforce ID whose key prefix maps to a Contact, Lead, Prospect, or CampaignMember.
  • campaignId, when provided, must be a valid Campaign ID.
  • flowId, when provided, requires campaignId and must be a valid flow definition ID.
  • When skipAudienceSelection is true, audience must still be non-empty. Otherwise, validation surfaces an error.
  • actionableListId, when provided, must be a syntactically valid Salesforce Id. audience must not be provided when actionableListId is. skipAudienceSelection is ignored.
  • defaultContent accepts 'LastSent' or 'None'. When omitted, defaults to 'LastSent'.

Modal Configuration 

The modal builds its step list dynamically, based on the configuration that you pass in.

ConfigurationSteps shown
audience onlyCampaign Picker → Audience Picker → Personalize → Preview & Send
audience and campaignId (campaign has one flow)Audience Picker → Personalize → Preview & Send
audience and campaignId (campaign has two or more flows)Campaign Picker (pre-filtered) → Audience Picker → Personalize → Preview & Send
audience and campaignId with flowIdAudience Picker → Personalize → Preview & Send (Campaign Picker skipped; flow loaded directly)
audience and skipAudienceSelection: trueCampaign Picker → Personalize → Preview & Send (Audience Picker skipped)
audience and campaignId with flowId and skipAudienceSelection: truePersonalize → Preview & Send
actionableListIdSame permutations as audience except no audience picker
defaultContentIndependent of other params. Only affects content initially selected for the selected template.

The Audience Picker step is currently available only for campaigns. To include it, pass a campaignId in the config. If your component is on a campaign record page, the campaignId isn’t provided automatically—read the campaign’s recordId from the record context and pass it as campaignId. For more information, see Use Record Context in a Lightning Web Component. Otherwise, the Audience Picker step isn’t included in the modal’s steps.

Note

Usage 

openDistributedMarketing is an imperative function, not a @wire adapter. Call it in response to a user action.

Launch the modal with only an audience.

1import { openDistributedMarketing } from "lightning/distributedMarketing";
2
3openDistributedMarketing({
4  audience: ["003xx0000001abcAAA", "00Qxx0000001xyzAAA"],
5});

Pre-filter to a campaign.

1openDistributedMarketing({
2  audience: contactIds,
3  campaignId: "701xx0000000001AAA",
4});

Launch directly into a specific flow.

1openDistributedMarketing({
2  audience: contactIds,
3  campaignId: "701xx0000000001AAA",
4  flowId: "300xx0000000001AAA",
5});

Skip the Audience Picker step for a mass action, such as a list view action.

1openDistributedMarketing({
2  audience: selectedCampaignMemberIds,
3  skipAudienceSelection: true,
4});

Error Handling 

All validation errors are thrown synchronously as DiscoError instances before the modal opens. Two error names are used.

Error NameThrown When
MISSING_REQUIRED_PARAMETERThe config object itself is missing.
INVALID_PARAMETERAny other validation failure occurs. Multiple failures are concatenated into a single message, separated by a pipe (|).

Wrap the call in a try and catch block when the configuration is derived from dynamic or untrusted input.

1try {
2  openDistributedMarketing(config);
3} catch (e) {
4  // e.name: 'MISSING_REQUIRED_PARAMETER' | 'INVALID_PARAMETER'
5  // e.message: human-readable, pipe-separated list of validation failures
6  console.error("DM launch failed:", e);
7}

Example 

This sample launcher component shows a single button. When a user clicks it, the component launches the Distributed Marketing modal with up to 2,000 campaign members from a specific campaign, pre-filters by that campaign, and skips the Audience Picker step.

Because the component passes a campaignId filter and the example campaign has only one flow, the single flow is auto-selected and the Campaign Picker step is skipped. The Audience Picker step is created in the modal steps, but skipAudienceSelection advances past it automatically. Users can go back and adjust their audience. As configured, the button advances the modal directly to the Personalize step.

The HTML template renders the launch button.

1<!-- myComponent.html -->
2<template>
3  <div class="slds-p-around_medium">
4    <lightning-button
5      variant="brand"
6      label="Launch DM"
7      title="Launch DM"
8      stretch
9      onclick={handleLaunch}
10    >
11      Launch DM (via public API)
12    </lightning-button>
13  </div>
14</template>

To query campaign members for the target campaign, use the lightning/graphql adapter. This example queries up to 2,000 campaign members, and passes the campaign member IDs to openDistributedMarketing when the user clicks the button.

1// myComponent.js
2import { LightningElement, wire } from "lwc";
3import { graphql, gql } from "lightning/graphql";
4import { openDistributedMarketing } from "lightning/distributedMarketing";
5
6const CAMPAIGN_MEMBER_QUERY = gql`
7  query getCampaignMembers {
8    uiapi {
9      query {
10        CampaignMember(where: { CampaignId: { eq: "701xx000003GaNPAA0" } }, first: 2000) {
11          edges {
12            node {
13              Id
14            }
15          }
16        }
17      }
18    }
19  }
20`;
21
22export default class MyCustomComponent extends LightningElement {
23  campaignMemberIds = [];
24
25  @wire(graphql, { query: CAMPAIGN_MEMBER_QUERY })
26  wiredCampaignMembers({ data, errors }) {
27    if (data) {
28      const edges = data?.uiapi?.query?.CampaignMember?.edges ?? [];
29      this.campaignMemberIds = edges.map((edge) => edge.node.Id);
30    }
31    if (errors) {
32      console.error("GraphQL CampaignMember error:", errors);
33    }
34  }
35
36  handleLaunch() {
37    try {
38      openDistributedMarketing({
39        audience: this.campaignMemberIds,
40        campaignId: "701xx000003GaNPAA0",
41        skipAudienceSelection: true,
42      });
43    } catch (error) {
44      console.error("Error launching DM modal:", error);
45    }
46  }
47}

The js-meta.xml file exposes the component for Lightning record pages, Experience Cloud site pages, and Flow screens. For more information, see XML Configuration File Elements.

1<!-- myComponent.js-meta.xml -->
2<?xml version="1.0" encoding="UTF-8"?>
3<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
4  <apiVersion>66.0</apiVersion>
5  <isExposed>true</isExposed>
6  <targets>
7    <target>lightning__RecordPage</target>
8    <target>lightningCommunity__Default</target>
9    <target>lightningCommunity__Page</target>
10    <target>lightning__FlowScreen</target>
11  </targets>
12</LightningComponentBundle>

Release Preview

This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.