Skip to main content

Its showing toast message but also showing this error box always ,I cant get why its showing 

 

Getting [NoErrorObjectAvailable] Script error.

import { LightningElement, track } from 'lwc';

import { subscribe, unsubscribe, onError } from 'lightning/empApi';

import { ShowToastEvent } from 'lightning/platformShowToastEvent';

export default class SubscribeToPlatformEvent extends LightningElement {

@track showMessage = false;

@track message = '';

channelName = '/event/Tata_Tele_Services__e';

isComponentConnected = true;

connectedCallback() {

onError(error => {

console.error('EMP API error: ', JSON.stringify(error));

});

}

subscribeToPlatformEvent() {

try {

const messageCallback = response => {

console.log('Message received:', response);

try {

if (!this.isComponentConnected) {

// Component is disconnected, no need to process the event

return;

}

const agentNumber = response.data.payload.Agent_Number__c

// Display a toast message for every incoming call

const toastEvent = new ShowToastEvent({

title: 'Incoming Call',

message: `Incoming call from ${agentNumber}`,

variant: 'info',

});

console.log('Successfully subscribed to : ', toastEvent);

if (this.isComponentConnected) {

this.dispatchEvent(toastEvent);

}

console.log('Successfully subscribed to : ', this.dispatchEvent);

} catch (error) {

console.error('Error handling message: ', JSON.stringify(error));

}

};

// Subscribe to the Platform Event

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

console.log('Successfully subscribed to : ', JSON.stringify(response));

});

} catch (error) {

console.error('Error subscribing to platform event: ', JSON.stringify(error));

}

}

// Unsubscribe when the component is destroyed

disconnectedCallback() {

this.isComponentConnected = false;

unsubscribe(this.channelName);

}

}

HTML

<template>

<lightning-card title="Incoming Call">

<div class="slds-m-around_medium">

<!-- Remove "utility:" prefix from icon-name -->

<lightning-icon icon-name="down" size="small"></lightning-icon>

<lightning-button label="Subscribe" onclick={subscribeToPlatformEvent}></lightning-button>

<div if:true={showMessage}>

<p>{message}</p>

</div>

</div>

</lightning-card>

</template>

#Integration  #Platform-events  #LWC  #LWC Framework

4 respuestas
  1. 12 ago 2025, 16:45

    The [NoErrorObjectAvailable] Script error you're seeing, suggests that there's an issue with a script running in your Salesforce org. This error commonly arises in situations where there is an uncaught JavaScript exception or an issue in the LWC component that is affecting the user interface.

0/9000