6

As an ISV, I need to establish communication between LWC and Visualforce page. I am planning to leverage LMS and I have 2 questions:

  1. Which are the best practices regarding Lightning Message Channels? Should I create them granular, 1 message channel for each event/purpose; or on the other hand should I create a generic Message Channel with couple of generic fields, like in this example?

  2. In the Visualforce developer guide the documentation states: Do not include a message channel in a package that you plan to install into production orgs. The installation will fail. As per my understanding, this statement is wrong, since including a message channel in a package does not cause the installation to fail, we have tested it. Does it mean Do not include in a package a Visualforce page that is using LMS? I would like to know if anyone has tried and can confirm it, because I have tried it as well and it works properly when installed in a developer org.

2 Answers 2

3
  1. The real answer, is that it depends and it's probably opinionated. However, I think one channel can be a valid choice. You don't even really need to define the message field as noted in this answer. There could be good reasons to have multiple channels:
  • Expose channel outside of namespace
  • Subscribers import/deal with only their topics/channels they need to
  • Separation of components, easier to understand

However, you do have options for complex payloads that can make it easy for the subscriber to filter out whatever messages they actually need with key/value payloads.

const message = {
    key: "some unique topic key",
    data: {value: "some value"}
};

publish(this.messageContext, YOUR_CHANNEL, message);
  1. You have to be careful when looking at the docs, to check the API version you're looking at. Your link is for API 47 (LMS was just added as developer preview) and is out-dated information. For historical context, you can cycle through API versions and see packaging was added later.

enter image description here

When you update it to the latest release (API 52), that confusing line you quoted is not there anymore and it matches with the Developer Guide's messaging which confirms it is available to package and install

When including message channels in packages that you publish on AppExchange, 1GP and 2GP packages are supported.

1
  1. From my experience I try to separate them logically and to minimize potential if/else in subscribers, if you have a general-purpose LMS where all subscribers should react somehow to messages, then it's good. If your subscribers need to do something only for 1 in thousand messages, then I think you should probably split it, so it's easier to understand, read, maintain, debug.

  2. Ye, now it works. I do have a working LMS in VF in package on Prod)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .