1

I am trying to pull 2 parameters from an LMS message. Currently they are coming in as null at the way I am grabbing them. The publish and subscribe methods work, as I threw console statements to track everything, but I am seeing an error when I try to assign the vars as null from my apex class that uses them..

Publisher JS:

handleClickedMedia(event){
     let selectedIdValue = event.currentTarget.getAttribute("data-key");
     this.newMediaId = event.currentTarget.getAttribute("data-key");
     const message = {
          mediaId: selectedIdValue, mediaList:this.mediaList
     };
     publish(this.messageContext, navigationMessageChannel, message);
     publish(this.dataMessageContext, dataMessageChannel, message);
}

Handler JS:

subscription = null;
  @wire(messageContext)
  messageContext;
  subscribeToMessageChannel(){
        if(!this.subscription){
              this.subscription = subscribe(
                    this.messageContext,
                    dataMessageChannel,
                    (message) => this.handleMessage(message),
                    {scope: APPLICATION_SCOPE}
              );
        }
  }
handleMessage(message){
     this.mediaId = message.mediaId;
     thhis.mediaList = message.mediaList;
}

also tried :

handleMessage(message)(){
         this.mediaId = message.parameters.mediaId;
         thhis.mediaList = message.parameters.mediaList;
    }
10
  • also tried message.details.mediaId; and message.detail.mediaId; Feb 10 at 1:46
  • How are you handling subscribing to the message channel? Are you passing in {message} => this.handleMessage(message)? What does console.log(message) show in handleMessage? Feb 10 at 3:35
  • @KrisGoncalves Yes I am handling the message channel similar to this developer.salesforce.com/docs/component-library/documentation/… when I console.log(JSON.stringify(message) I get the ' "mediaId" : "123", "mediaList" :"1234" ' Feb 10 at 3:37
  • Can you also add the method that subscribes to this message-channel? Feb 10 at 3:38
  • @SachinHooda sure, give me a moment to add Feb 10 at 3:39

1 Answer 1

1

I solved the issue, the issue was that the mediaList and mediaID would become null because of the connectedcallback they were in. I moved the function callout to after the assigning of vars and it fixed it.

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.