
Lightning Message Service
Important Summer’20 Update: Lightning Message Service is now GA! Details here.
Lightning Message Service can be used to exchange data bidirectionally between Aura, LWC and Visualforce components.
One example i would like to show you today how we can initiate a simple lightning toast event from a Visualforce page’s Javascript function.
To begin with, you would need a message channel component deployed in your org. A message channel acts like an envelope containing messages and parameters that you wish to pass between the component. Salesforce UI currently doesn’t support creating the message channel directly. So you would have to create and deploy using ANT, Workbench or use VS Code. A message channel looks something like this →
Next Step is to create a Visualforce page where we use our message channel to publish an event:
Last step - Our Lightning Web component subscribing to the messages received from Message Channel. I have only included the JS File as the main HTML is empty & not relevant for this example.
and Finally →
Limitations to consider
LMS doesn’t currently support these Salesforce experiences and tools: Salesforce Mobile app, Lightning Out and Lightning Communities
LMS cannot be used to communicate with VF page contained in an iframe in Aura/LWC.
When including message channels in packages that you publish on AppExchange, only 1GP packages are supported.
A message is a serializable JSON object.
Full release notes on this feature can be found here:
Spring 20 → https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_lc_message_channel.htm
Summer 20 → https://releasenotes.docs.salesforce.com/en-us/summer20/release-notes/rn_lc_message_channel.htm