Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.

#Trailhead Challenges2,397 discussing

Hands-on challenges are the “secret sauce” of Trailhead. Before searching for solutions to superbadge challenges, review the Salesforce Certification Program Agreement and Policies.

 I am getting this error how should i slove this can any me help me 

this is myCode 

import { LightningElement, track } from 'lwc';

import { ShowToastEvent } from 'lightning/platformShowToastEvent';

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

 

export default class DisconnectionNotice extends LightningElement {

    channelName = '/event/Asset_Disconnection__e';

    subscription = null;

    @track status; // Tracks the disconnection status

    //  messageCallback;

    // Subscribe to the Platform Event

    connectedCallback() {

        this.subscribeToEvent();

    }

 

    // Unsubscribe from the Platform Event

    disconnectedCallback() {

        this.unsubscribeFromEvent();

    }

 

    // Define the messageCallback function

    messageCallback = (response) => {

        console.log('New event received: ', JSON.stringify(response));

        const payload = response.data.payload;

        this.status = payload.Disconnected__c;

 

        if (this.status) {

            this.showSuccessToast('Asset Disconnected Successfully!');

        } else {

            this.showErrorToast('Asset Disconnection Failed.');

        }

    };

 

    // Subscribe to the Platform Event

    subscribeToEvent() {

        subscribe(this.channelName, -1, this.messageCallback)

            .then((response) => {

                console.log('Subscription successful: ', JSON.stringify(response));

                this.subscription = response;

            })

            .catch((error) => {

                console.error('Subscription failed: ', error);

            });

 

        // Handle errors

        onError((error) => {

            console.error('Streaming API error: ', error);

        });

    }

 

    // Unsubscribe from the Platform Event

    unsubscribeFromEvent() {

        if (this.subscription) {

            unsubscribe(this.subscription, (response) => {

                console.log('Unsubscribed from event: ', JSON.stringify(response));

            });

        }

    }

 

    // Show Success Toast

    showSuccessToast(message) {

        const event = new ShowToastEvent({

            title: 'Success',

            message: message,

            variant: 'success',

        });

        this.dispatchEvent(event);

    }

 

    // Show Error Toast

    showErrorToast(message) {

        const event = new ShowToastEvent({

            title: 'Error',

            message: message,

            variant: 'error',

        });

        this.dispatchEvent(event);

    }

}

 

 

#Trailhead Challenges

0/9000
6 answers
  1. Eric Burté (DEVOTEAM) Forum Ambassador
    Jan 24, 2024, 1:14 PM

    Hello @Ugandhar Reddy Mallakunta, strange you are stuck at the publication... I would imagine that this was the trigger that was not ok, but from this error message I understand that the validation script did not succeed creating the platform event (which you normally have to capture with the trigger you have made in this unit). 

    Have you well validated the previous unit (https://trailhead.salesforce.com/content/learn/modules/platform_events_basics/platform_events_define_publish) ?

    Eric

0/9000