You create a Message Channel as metadata in a Salesforce DX project, then deploy it so components can publish and subscribe. There is no point-and-click builder for the channel itself. You author the XML, save it in the right folder, and push it to the org.
- Create the messageChannels folder
In your Salesforce DX project, make sure the path force-app/main/default/messageChannels exists. This is where every Message Channel definition lives alongside the rest of your source.
- Add the channel file
Create a file named for your channel using the format channelName.messageChannel-meta.xml, for example ContactSelected.messageChannel-meta.xml. The file name before the extension becomes the channel's API name.
- Declare the channel contract
In the XML, set the masterLabel, an optional description, the isExposed flag, and one or more lightningMessageFields. Give each field a fieldName so publishers and subscribers know what the payload should contain.
- Deploy and reference it
Deploy the metadata to your org. In a component, import the channel from @salesforce/messageChannel using its API name with the __c suffix, then call publish or subscribe from lightning/messageService.
The human-readable label for the channel, shown where channels are listed. Required for a valid channel definition.
Boolean that decides whether components in other namespaces may use the channel. Defaults to false, which keeps the channel private to its own namespace.
One or more field entries, each with a fieldName, that document the shape of the message payload the channel carries.
- Reference the channel with its __c suffix in the import, for example @salesforce/messageChannel/ContactSelected__c, or the import fails to resolve.
- Leave isExposed at false unless another namespace truly needs the channel. Exposing it lets outside packages publish to and subscribe on it.
- Always unsubscribe in disconnectedCallback. Subscriptions that are never cleaned up keep running and degrade page performance over time.
- Scope can only be set on the subscriber, and only with @wire(MessageContext). You cannot scope a publisher.