Skip to main content Únase a nosotros en TDX, en San Francisco, o en Salesforce+ los días 5 y 6 de marzo en la conferencia para desarrolladores sobre la era de agentes de IA. Registrarse ahora.

#Trailhead Challenges2399 debatiendo

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 trying to complete the Subscribe to Platform Events, within the Platform Events Basics, but keep getting the same error message in my devConsole. It is the same Playground I completed the other two parts of the module in. Here is a screenshot after I try going through Debug. I have tried troubleshooting various ways (including not capitalizing the word trigger) so any help would be appreciated. Thank you! 

Subscribe to Platform Events error with 'trigger'

 

 

 

#Trailhead Challenges

0/9000

 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
7 respuestas
0/9000
3 respuestas
  1. Eric Burté (DEVOTEAM) Forum Ambassador
    23 ago 2024, 8:52

    Hello @Jayalakshmi Kuruba please see the following documentation article to check if you well subscribed to platform events

    https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_apex.htm

    Eric

0/9000

I did everything in the challenge to publish an Order Event, created the platform event, added the checkbox field, did the trigger, but I am unable to proceed as it keeps saying it failed to publish the event

 

#Trailhead Challenges

6 respuestas
0/9000