Get live notifications when the record you’re viewing gets modified

Fabien Taillon
Texeï
Published in
3 min readAug 27, 2018

--

Winter ’19 introduces a new component, lightning:empApi, that lets you easily receive streaming events directly in your Lightning Components. Another new feature that comes in Developer Preview in Winter ’19 is Change Data Capture. What’s best than doing a demo component to test these 2 new features ?

Change Data Capture

Change Data Capture is a really powerful feature that will send notification everytime a record is created, updated, deleted or undeleted. This is very handy to keep data consistent across all your applications. No need anymore to setup Workflows, Process Builder or Triggers, this comes out of the box for just one click.

You activate Change Data Capture per sObject directly in Setup:

So far all custom objects are supported, however only a subset on standard objects are, have a look here to get the whole list.

Note: At the time of writing, Change Data Capture is still in Developer Preview. When it goes GA, have a look to the updated list of supported sObjects, limits and pricing.

To test my component, I activated it in my Scratch Org for a standard object and a custom object.

Using the component

The code of the component is available in my GitHub here:

Once you’ve added the component to your org, just go to the record page of your object (if you’ve activated Change Data Catpure for Account, let’s do it on the Account page), edit it in App Builder and add it to the page.

Don’t add it inside a tab as these are lazy loaded, the component would not be loaded if you don’t click on this specific tab (and thus notification wouldn’t work).

That’s it ! Next time someone else modifies the record you’re viewing, you’ll see a notification like this at the top of the page:

How it works

The component markup is pretty basic, the only thing to notice is the use of lightning:empApi component:

The controller is a little bit longer, but don’t worry, nothing groundbreaking here…

> > > Click here to read the full article < < <

Click here to access all Texeï blog posts

--

--

Salesforce MVP | CTO @TexeiFrance | @ParisDUG Co-organizer | @FTDreamin Team