How to use Platform Event in lightning by using lightning:empApi

Understanding :

Salesforce introduced a new component lightning:empApi with winter 19 to support streaming API.

Before Winter 19

Prior to winter 19 in order to use the streaming API, we need to upload the CometD javascript libraries, as a static resource. We needed to use cometD by using ltng:require along with afterscriptsloaded .

After Winter 19

But with the new EmpJs Streaming API library which subscribes to a streaming channel and listens to event messages using a shared CometD connection without using the CometD static resource.

This component is supported only in desktop browsers. In addtion, this component provides access to methods for subscribing to a streaming channel and listening to event messages. All streaming channels are supported, including channels for platform events, PushTopic events, generic events, and Change Data Capture events. The lightning:empApi component uses a shared CometD connection.

This example subscribes to a channel when you click the Subscribe button. The channel is specified in an input component. The default value provided is an example platform event channel.

Consider the following code:
Following is the trigger which publishes the event on account update:
Output:

lightning:EmpApi Gif

For more details refer to
https://developer.salesforce.com/docs/component-library/bundle/lightning:empApi

Write a Response

Your email address will not be published.


Find Out How We Can Help

If you're ready to find out more about how SimplusLabs can help energize your workers, your customers, and your business with a different experience, let's talk.