I am trying to publish a message form lWC , but getting error as below:
lightning/messageService: invalid message context]
i have created the message channel file added it in the package.xml and deployed it to the org, below is my codes not sure any mistake i am making. below is my code :
LMS MetaFile:
<?xml version="1.0" encoding="UTF-8"?>
<fieldName>messageText</fieldName>
<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>SampleMessageChannel</masterLabel>
<isExposed>true</isExposed>
<lightningMessageFields>
<description>Holds the message to display</description>
</lightningMessageFields>
</LightningMessageChannel>
LWC Code
import { LightningElement, wire } from 'lwc';
import messageChannel from '@salesforce/messageChannel/Sample__c';
import {publish, MessageContext} from 'lightning/messageService'
export default class Publisher extends LightningElement {
@wire(MessageContext)
messageContext;
handleButtonClick() {
let message = {messageText: 'This is a test'};
publish(this.messageContext, messageChannel, message);
}
}
fieldName
or have you forgotten it to put it in code above? I see onlydescription
. Second why are you importingSample__c
when you have deployedSampleMessageChannel