2

I was thinking - while publishing or subscribing to a LightningMessageChannel, the payload has to be in some way match exactly to the names or fields defined in the lightningMessageFields XML definition of the channel. Found out my code/components are working without any consideration to the actual names used in the lightningMessageFields. Whatever I send to the channel( by any name ) I can get back and process in the subscribing component. Am I doing something wrong here or is there any special benefit sticking to the fields defined? if so where can I find details of usage patterns for this specific aspect of LightningMessageChannel fields?

1 Answer 1

1

It is correct and as per design that the LightningMessageChannel fields are not reference-checked and you can add in a message field in the message of your choice. While the channel name is strictly checked!

I think it's left open because some developers (coming from JavaScript background) do not like strict behavior (A message is a mutatable JavaScript Object) while fellow salesforce devs are used to Salesforce Metadata and like to keep it strict and version it.

It's left as it is for now but hopefully, in the future (safe harbor) there is an additional switch to toggle this behavior!

1
  • Thank you so much. All makes sense now. Pretty much all the examples and samples out there use "message" as a field in XML as well as in subscriber component and in publisher component which made me think this "message" is somehow magically connected and the same across. I'll rename my subscriber message to messageRx and publisher message to messageTx (something to that effect) so that whoever maintains my code not that familiar with channels will not get confused. Thank you
    – vinod
    Dec 1, 2020 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.