Skip to main content

We have a 

handleSubscribe() function called from connectedCallback() function. handleSubscribe() has messageCallback function. When connectedCallback() is executed and handleSubscribe() function is entered we are able to access this.label

 object(which has properties coming from Custom Labels) and their property can be logged.  

 

When the 

messageCallback is executed and the logic within is run there we are not able to retrieve this.label values. The this.label is undefined. 

 

connectedCallback(){

this.isSpinnerLoading = true;

this.handleSubscribe();

checkApplicationStatus({hostApplicationRecordId: this.recordId})

.then(result=>{

if(result && result.validApplicationStatus === true){

this.invalidHostApplicationStatus = false;

if(result.associatedWithGoogleMeta){

this.isAssociatedWithGoogleMeta = true;

generateParticipantLinkOnStart({hostApplicationRecordId: this.recordId})

.then(result=>{})

.catch(error=>{

console.error(error);

})

.finally(()=>{

//this.isSpinnerLoading = false; //this should happen via the platform event

})

}

}

})

.catch(error=>{

console.error(error);

})

}

handleSubscribe() {

// Callback invoked whenever a new event message is received

const self = this;

const messageCallback = function (response) {

var obj = JSON.parse(JSON.stringify(response));

let objData = obj.data.payload;

self.disableSendButton = !objData.DS_Links_Generated__c;

if(self.isSpinnerLoading){

self.isSpinnerLoading = false;

}

//toast links generated message

const evt = new ShowToastEvent({ //get user to select an option first

title: 'Success',

message: this.labels.dsGeneratedSuccessMessage,

variant: 'success',

});

this.dispatchEvent(evt);

};

// Invoke subscribe method of empApi. Pass reference to messageCallback

subscribe(this.channelName, -1, messageCallback).then(response => {

// Response contains the subscription information on subscribe call

this.subscription = response;

});

}

 

 

this.label is undefined when messageCallback function runs.

 

 

Could you please let me know what is the problem here? How can we retain the value for this.label when messageCallback is executed. What would be the right approach to retain the value / how can we still able to access the value?

 

Please help!!! 

  

@Salesforce Certified Professionals@* Salesforce Developers *@Lightning Components Development

5 risposte
0/9000