10

I need to detect record-updates by different sources as stated here: Lightning Components: how to use events to detect record updates?

For this example, I'm using the standard Record Detail compo on a Flexipage.

I don't like it, but unfortunately the only viable approach seems to handle the force:refreshView seem to be the only way to detect updates. I handle them like like that:

Markup

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

Controller

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

Result

Now 'HANDLER' appears exactly 4 times in my console per subscribing component I have on the Flexipage. Why that?

Expected

Each handler should get called once per subscribing component.

3
  • Uwe, aren't your other two components also calling this handler each time they're run? If so, an Update event would also seem to cause the Save event to fire. If these are all being triggered by some other action that triggers this handler, you'd seem to get recursion causing it to fire multiple times.
    – crmprogdev
    Commented Jan 11, 2017 at 15:01
  • @crmprogdev No, I can definitively rule that out: I've written my own Record Edit component, which is base on <force:recordView ... type="FULL"/> which is firing exactly once. I put my custom compo and the Standard Record Detail above each other: using standard, I get 4x bombarding, using my, I receive just 1x hit (exactly as expected). That message-system is really driving me nuts - in general, not only this issue...
    – Uwe Heim
    Commented Jan 11, 2017 at 18:00
  • The feature you're really looking for to handle and perform record updates is called Lightning Data Service, and it's currently in developer preview. developer.salesforce.com/docs/atlas.en-us.lightning.meta/… Commented Jan 18, 2017 at 15:47

2 Answers 2

2

I just created a new custom object, and created a handler component with your code above. Hitting the standard edit action, and then hitting save, I have one "HANDLER" in my javascript console, and the Lightning Inspector plugin only shows one force:refreshView being fired.

I would recommend recording your interaction in the Inspector plugin and viewing the event log to identify when and what components specifically are firing the event. I suspect something more complicated is going on that a simple record save.

Inspector Screenshot

Additional reading on how to use the events inspector can be found here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/inspector_events.htm.

1
  • Thanks, I'll review the scenario in more isolation and with the event inspector.
    – Uwe Heim
    Commented Jan 12, 2017 at 0:05
1

Only workaround I found so far is building a throttle

<aura:attribute name="refreshTimestamp" type="Integer" default="0" />

forceRefreshViewHandler : function(cmp, evt, hlp){
    var lastRefresh             = cmp.get("v.refreshTimestamp")
    if( hlp.ts() - lastRefresh > 1000 ) {
        // doing my stuff here
        cmp.set("v.refreshTimestamp" , hlp.ts() );
    }
}   

The standard component is hammering usually it's 4 bullets within less than 50ms so it seems to work. But hackish as hell and still no explanation why it's necessary at all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .