The lightning:empApi component gives methods for subscribing to a streaming channel and listening to event messages. It supports all streaming channels including channels for platform events, pushTopic events and Change Data Capture events. The lightning:empApi component uses a shared CometD connection.
Note:
If you want to learn more about platform events then refer below blog:
Platform Events : Way to Deliver Custom Notifications within Salesforce or to external Applications
I have created a lightning component which will subscribe to platform event "Demo_Event__e" which we have created in our previous blog.
I have created an app page using lightning app builder named as "Platform Events App Page". and added this lightning component into it.
Code Snippet:
Below is snapshot of Lightning App page before platform event is fired.
Now fire platform event using workbench through REST API call
Platform event notification received in lightning component.
Note:
- This component is available in 44.0 api version or later.
- This is available in Lightning Experience and only supported in desktop browsers.
If you want to learn more about platform events then refer below blog:
Platform Events : Way to Deliver Custom Notifications within Salesforce or to external Applications
I have created a lightning component which will subscribe to platform event "Demo_Event__e" which we have created in our previous blog.
I have created an app page using lightning app builder named as "Platform Events App Page". and added this lightning component into it.
Code Snippet:
Below is snapshot of Lightning App page before platform event is fired.
Now fire platform event using workbench through REST API call
Platform event notification received in lightning component.
Hope this will help to understand platform events handling in lightning components.
Looking forward for everyone's suggestions and comments!!!

