function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Roy SouravRoy Sourav 

LMS - "invalid message context" error.

We are facing issues with Lightning Message Service. We are using a LWC component in experience builder which publishes the message using LMS. Please find below error message while publishing the message.

Error details
Error details



We are using all standard code as per the below documentation - 

1. we have subscribed to the message channel in our community.
import SAMPLECHANNEL from '@salesforce/messageChannel/SampleMessageChannel__c';
2. we have imported the pusblishMessage , MessageContext.
import { publish, MessageContext } from 'lightning/messageService';
3. We have also use the wire context.
 @wire(MessageContext) messageContext;
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_message_channel


Need help from the Ohana community..!! Please help..!!
Carolyn CroceCarolyn Croce
I also have this same question and I cannot find any proper answers on the internet and also need a solution. https://www.erewards.run/
Tanay GuptaTanay Gupta
I faced the same problem, turns out instead of using @wire(MessageContext) , use createMessageContext() method. (Just a workaround)
import { createMessageContext} from 'lightning/messageService';

messageContext = createMessageContext();
Then simply use 'this.messageContext' for any LMS operation.
 
Rajat Bajaj 14Rajat Bajaj 14
This error can be resolved by referencing the messageContext variable, using this keyword as it is defined on class level. 
Tejas GaikwadTejas Gaikwad
1. Probably you are calling the publish method from some promise (the apex method). 
2. check if the messagecontext variable name is correct in the publish