Create a Message Channel
To create a Lightning message channel, use the LightningMessageChannel metadata type.
To deploy a LightningMessageChannel into your org, create an SFDX project. Include the XML definition in the force-app/main/default/messageChannels/
directory. The LightningMessageChannel file name follows the format messageChannelName.messageChannel-meta.xml
.
For an example metadata file, see Metadata API Developer Guide: LightningMessageChannel.
To add it to your scratch org or another type of org, such as a sandbox or a Developer Edition org, run sf project deploy start
.
Here’s how to import a Lightning message channel that a component can use to communicate via the Lightning Message Service.
Record_Selected__c
refers to a custom instance of the LightningMessageChannel metadata type. Although it uses the __c
suffix, it isn’t a custom object.
channelName
—An imported symbol that identifies the message channel.channelReference
—The API name of the message channel in the formatChannel_Name__c
.namespace
—If the message channel is in a managed package, this value is the namespace of the managed package. If the message channel is not in a managed package, do not include a namespace.
The lwc-recipes repo has a messageChannel-meta.xml example.