Communicating Across the DOM with Lightning Message Service
Use Lightning message service to communicate across the DOM within a Lightning page. Communicate between Visualforce pages embedded in the same Lightning page, Aura components, and Lightning web components, including components in a utility bar and pop-out utilities. Choose whether a component subscribes to messages from the entire application, or from only the active area.
If you’re switching from Salesforce Classic to Lightning Experience, you can build Lightning web components that can communicate with existing Visualforce pages or Aura components. You can also use Lightning message service to communicate with softphones via Open CTI.
Lightning message service is available in Lightning Experience and as a beta feature for Lightning components used in Experience Builder sites.
To access Lightning message service in Aura, use the lightning:messageChannel component. A message is a serializable JSON object. Examples of data that you can pass in a message include strings, numbers, booleans, and objects. A message can’t contain functions and symbols. The lightning:messageChannel component is only available in Lightning Experience.
-
To create a
lightning:messageChannelcomponent in your org, use the LightningMessageChannel metadata type and append it with__c. The message channel isn’t a custom object, it just uses the same suffix. -
To publish a message on a message channel, include a
lightning:messageChannelcomponent in your Aura component and use thepublish()method in your Aura component’s controller file. -
Subscribe to a Message Channel
To subscribe to a message channel, create a handler method to run when it receives a message.
-
Lightning Message Service Limitations
Keep the following in mind when working with Lightning message service.
See Also
- Blog: Lightning Message Service
- Lightning Web Components Developer Guide: Communicating Across the DOM with Lightning Message Service
- Visualforce Developer Guide: Communicating Across the DOM with Lightning Message Service
- Open CTI Developer Guide: Lightning Message Service Methods for Lightning Experience