function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
test vijaytest vijay 

Platform Event Errors In Lwc

Hi Guys,
Greetings,
I want to call a Lwc Js Method when a standard case or any object update.I think It's possible for platform event but I am not able.
I tried empApi but not got success yet. 
I did follow following refering steps but not worked.
reference : https://newstechnologystuff.com/2020/08/15/platform-event-in-lightning-web-components/

can someone show me right way how to complete my requirment.
ShivankurShivankur (Salesforce Developers) 
Hi Ravi,

You can subscribe to platform events with the empApi component in your Lightning web component.The empApi component provides access to methods for subscribing to a streaming channel and listening to event messages.

The empApi component uses a shared CometD-based Streaming API connection, enabling you to run multiple streaming apps in the browser for one user. The connection is not shared across user sessions.

To use the empApi methods in your Lightning web component, import the methods from the lightning/empApi module as follows.
import { subscribe, unsubscribe, onError, setDebugFlag, isEmpEnabled } 
    from 'lightning/empApi';

You will find a perfect code example here to try with:
https://developer.salesforce.com/docs/component-library/bundle/lightning-emp-api/documentation

To Subscribe and Unsubscribe from a Message Channel, follow below link:
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/use_message_channel_subscribe

For some additional insight:
https://www.v2force.com/blogs/publish-subscribe-model-in-lightning-web-component-lwc-part-2-salesforce-blog/

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.