I am trying to publish data from Aura to LWC. I am getting error to rectify what I am missing. I checked multiple examples as syntax wise, still didn't work. Hence posting to see if anyone can help out.
Aura Component html:
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<a href="javascript:void(0);" onclick="{!c.publishMC}">More Information</a>
<lightning:messageChannel type="AlertMessageChannel__c" aura:id="AlertMessageChannel"></lightning:messageChannel>
</aura:component>
Aura Controller JS:
({
publishMC : function(component, event, helper) {
var messageInfo = [
{ normalTxt: '', boldTxt: '', boldLeftTxt: 'This opportunity is Stale',
normalRightTxt: 'the stale reason code is EOD PAST DUE.'},
{ normalTxt: '', boldTxt: '', boldLeftTxt: 'This account has 1 or more Frame
Agreements', normalRightTxt: 'There is a Frame Agreement associated to the account,
if applicable, please link to this opportunity using the Contract ID field.'},
];
component.find("AlertMessageChannel").publish(messageInfo);
}
})
I have also added Message Service xml file too
<?xml version="1.0" encoding="UTF-8"?>
<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
<description>This is a alert message channel communicator</description>
<isExposed>true</isExposed>
<lightningMessageFields>
<description>Header information passed into alert modal window</description>
<fieldName>alertHeaderInfo</fieldName>
</lightningMessageFields>
<lightningMessageFields>
<description>Body information passed into alert modal window</description>
<fieldName>alertBodyInfo</fieldName>
</lightningMessageFields>
<lightningMessageFields>
<description>Show/Hide information passed into alert modal window</description>
<fieldName>alertVisibleInfo</fieldName>
</lightningMessageFields>
<masterLabel>AlertMessageChannel</masterLabel>
But when try to load, getting error as :
Action failed: lightning:messageChannel$controller$init [Lightning Message Service - unrecognized MessageChannel reference: AlertMessageChannel__c]
Can any one help me, what I am missing?
The message seems to indicate that your Message Channel is not being recognized. The "masterLabel" is not the API name of your message channel, but rather the filename is. For instance if you have your xml defined in a file AlertMessageChannel.messagechannel-meta.xml then you can reference your channel with "AlertMessageChannel__c". If your filename is something different, like "TestChannel.messageChannel-meta.xml" then you have to use "TestChannel__c".