3

When a dispatch event or an imperative apex call is made from a streaming api callback, then it throws this error in browser console window and reloads the page .

 {"event":{"descriptor":"markup://aura:invalidSession","attributes":{"values":{}},"eventDef":{"descriptor":"markup://aura:invalidSession","t":"APPLICATION","xs":"I","a":{"newToken":["newToken","aura://String","I",false]}}},"exceptionEvent":true}

CallBackCode :


    // Callback invoked whenever a new event message is received
    messageCallback = (response) => {
        try {
            let parsedData = JSON.parse(JSON.parse(JSON.stringify(response)).data.payload);
            if (parsedData.resultMessage.indexOf('Successfully') > -1) {
                // Here if we call an imperative apex or dispatch an event, then it throws the error and reloads the page.
                window.dispatchEvent(
                    new CustomEvent('streamingsuccess', {
                        detail: {
                            payload: parsedData
                        }
                    })
                );
                this.handleUnsubscribe();
            } else {
                this.handleUnsubscribe();
                this.boolSourceOauthDisabled = false;
            }
            this.boolSourceIsLoaded = !this.boolSourceIsLoaded;
        } catch (e) {
            console.error(e);
        }
    };

    handleSubscribe() {
        // Invoke subscribe method of empApi. Pass reference to messageCallback
        subscribe(this.channelName, -1, this.messageCallback).then(response => {
            // Response contains the subscription information on subscribe call
            console.error('Subscription request sent to: ', JSON.stringify(response.channel));
            this.subscription = response;
        });
    }

Has anyone faced this issue and how to fix this?

Even if I use the messageCallback inside handleSubscribe, same issue occurs and the page reloads.

handleSubscribe() {

    // Callback invoked whenever a new event message is received
    const messageCallback =  (response) => {
        try {
            let parsedData = JSON.parse(JSON.parse(JSON.stringify(response)).data.payload);
            if (parsedData.resultMessage.indexOf('Successfully') > -1) {
                // Same error here, if I use a dispatch event , postMessage or an imperative apex call.
// Also as I have to call an apex call here, I tried to call dispatch event or post message from here. And as soon as I access `this` from the `message` event callback, it throws that error again and reloads the page.
                   
            }

        } catch (e) {
            console.error(e);
        }
    }


    // Invoke subscribe method of empApi. Pass reference to messageCallback
    subscribe(this.channelName, -1, messageCallback).then(response => {
        // Response contains the subscription information on subscribe call
        console.error('Subscription request sent to: ', JSON.stringify(response.channel));
        this.subscription = response;
    });
}

Has anyone tried this approach yet?

5
  • Instead of window.dispatch, did you try this.dispatch? – salesforce-sas Jul 31 '20 at 2:58
  • tried that, nothing works. Even if I try to directly call imperative apex, it fails with same error message and reloads the page – Nagendra Singh Jul 31 '20 at 3:13
  • can you try this.messageCallback.bind(this) – salesforce-sas Jul 31 '20 at 3:42
  • Same error message , {"event":{"descriptor":"markup://aura:invalidSession","attributes":{"values":{}},"eventDef":{"descriptor":"markup://aura:invalidSession","t":"APPLICATION","xs":"I","a":{"newToken":["newToken","aura://String","I",false]}}},"exceptionEvent":true} – Nagendra Singh Jul 31 '20 at 3:53
  • I will try this when I get some time and let you know – salesforce-sas Jul 31 '20 at 7:54
1

The issue was related to Api Version of Apex class, once I reduced it to 48 from 49. It worked well.

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.