Hello,
Could someone please tell me how to get the data from subscribed object. I tried but I am unable to fetch the data . I want to show the subscribed data in a input field. I am getting data as a object in contactList but I am unable to assign that data in name field , phone field and email field. From published method I am sending olddata available in contact object and updated data in contact contact.
conList=updated data
oldValue=old data
Subscribed Component:
import { LightningElement, track, wire } from 'lwc';
import {subscribe, MessageContext, APPLICATION_SCOPE, unsubscribe } from 'lightning/messageService';
import SAMPLEMC from "@salesforce/messageChannel/MyMessageChannel__c";
export default class LMSEditRecordChildComponent extends LightningElement {
@track contactList;
subscription;
@wire(MessageContext) messageContext;
connectedCallback(){
this.subscription = subscribe(this.messageContext, SAMPLEMC, (message) => {
this.displayMessage(message)}, {scope:APPLICATION_SCOPE});
}
subscribeMC() {
if (this.subscription) {
return;
}
this.subscription = subscribe(this.messageContext, SAMPLEMC, (message) => {
this.displayMessage(message)}, {scope:APPLICATION_SCOPE});
}
unsubscribeMC() {
unsubscribe(this.subscription);
this.subscription = null;
}
displayMessage(message) {
this.contactList = message ? JSON.stringify(message, null, '\t') : 'no message payload';
}
disconnectedCallback() {
}
}
Published Component: (published Method)
publishHandler(){
const message={
recordData: this.conList,
oldData: this.oldValue
}
publish(this.messageContext, SAMPLEMC, message);
}