Lightning Message Service

Aryakaran Gupta
2 min readApr 29, 2020

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 →

Message Channel

Next Step is to create a Visualforce page where we use our message channel to publish an event:

Visualforce Page

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.

Lightning Web Component

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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Aryakaran Gupta
Aryakaran Gupta

Written by Aryakaran Gupta

Salesforce Enthusiast & Lightning Specialist

No responses yet

Write a response