Thursday, May 16, 2019

Handling Platform Events in Lightning Components

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:
  • This component is available in 44.0 api version or later.
  • This is available in Lightning Experience and only supported in desktop browsers.
To call the component's methods, add the lightning:empApi component inside your custom component and assign an aura:id attribute to it.

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!!!


10 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. best texting service

    ReplyDelete
  3. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. simply buzzes

    ReplyDelete
  4. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. pipedrive pricing

    ReplyDelete
  5. Thanks a lot for sharing this excellent info! I am looking forward to seeing more posts by you as soon as possible! I have judged that you do not compromise on quality. material equipements for handling

    ReplyDelete
  6. The article looks magnificent, but it would be beneficial if you can share more about the suchlike subjects in the future. Keep posting. sviluppo siti web Milano

    ReplyDelete
  7. A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. 1000 Pip Builder Forex Signals Review

    ReplyDelete
  8. I would make sure the site looked professional of course, I believe that having quality photography and a clean design are the two best ways to get a professional site. I would have a very limited amount of outgoing links on my main page and NO BANNERS from directories. Webdesign

    ReplyDelete
  9. Is there a way to subscribe to platform events for a specific records updates? I am working on Account "Target Corp", and an event was published for Target Corp. Is there a way to display that the message using EMPAPi to users only working on Target Corp?

    ReplyDelete