[SalesForce] Lightning Components: how to use events to detect record updates

I have a custom Lightning Component sitting on a Flexipage for e.g. Account. Now I want to register an handler, which will be invoked each time, the record is updated. Updates might happen via

  • standard Record Detail component on the same Flexipage
  • other custom components on the same Flexipage
  • triggers

What's the best way to detect and handle as many of these updates as possible?

I've tried so far:

<aura:handler name="onUpdated" event="force:recordUpdated"action="{!c.events}" />
<aura:handler name="onSaveSuccess" event="force:recordSaveSuccess" action="{!c.events}"/>

with

events : function(cmp, evt, hlp){
    console.log('EVENTS :: ',evt.getName(),evt.getParams());
},

but nothing in the console so far. Any ideas?

Best Answer

Actually I'm using the event force:refreshView which is doing what I want:

<aura:handler event="force:refreshView" action="{!c.forceRefreshViewHandler}"/>

and in the controller

forceRefreshViewHandler : function(cmp, evt, hlp){
    // your logic here
},

If my stuff is making an update, which the flexipage should update on, I'm firing the very same event

$A.get("e.force:refreshView").fire();

Tricky part is, if two components are updating each others: then you have to set a flag or something to prevent endless loops.

Lots of Salesforce Standard components are firing and listening for this event, so it's pretty useful.

Caveats

  • updates made by triggers or API integrations probably get NOT detected
  • updates made by components not firing force:refreshView are not detected