Contents
What do you need to know about lightning empapi?
The lightning:empApi 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.
How to subscribe to lightning empapi in Salesforce?
To call the component’s methods, add the lightning:empApi component inside your custom component and assign an aura:id attribute to it. This example subscribes to a channel when you click the Subscribe button.
How do I add a channel to lightning?
First, we need to add lightning:empApi utility in the component. In doInit handler of JS Controller, we have to call a subscribe method of empApi utility and pass the channel and replayId. Channel contains the name of Event and replayId is used to get the new events.
How to publish a platform event in Lightning?
Type Platform Event in Quick Find box and click on Platform Events under Integrations. Click on the New Platform Event and provide Label and Plural Label. For Publish Behaviour, select Publish After Commit to publish the event only after the transaction is successful. Click Save.
What kind of API does Salesforce Lightning use?
All streaming channels are supported, including channels for platform events, PushTopic events, generic events, and Change Data Capture events. This component requires API version 44.0 or later. The lightning/empApi module uses a shared CometD connection, enabling you to run multiple streaming apps in a single browser session.
How are platform events created in EMP API?
Platform Events and fields are created in the same way we create Objects and fields. Type Platform Event in Quick Find box and click on Platform Events under Integrations. Click on the New Platform Event and provide Label and Plural Label.
How to subscribe to platform events in Lightning?
Subscribe to platform events with the empApi component in your Lightning web component or Aura component. The empApi component provides access to methods for subscribing to a streaming channel and listening to event messages.