4

I have a helper function called via a controller function and am calling it in two circumstances:

save : function(component, event, helper) {
    var action = component.get("c.replaceAllChildrenOfType");
    action.setParams({...});
    action.setCallback(this, function(response) {
        console.log('callback');
    });
    $A.enqueueAction(action);
    console.log('enqueued');
},

One circumstance is from a button on the component:

<lightning:button label="Temporary Save" onclick="{! c.save }"/>

where things go as expected with "enqueued" logged and then "callback" logged shortly afterwards with the server-side update having been done.

The other circumstance is via a method invoked from a separate component:

<aura:method name="save" action="{! c.save }"/>

where things do not go as expected with "enqueued" logged and then no "callback" logged at all with the server-side update having been done.

Can anyone explain?

PS

Further digging - for the aura:method case, the callback does happen if the call is made from a button click but does not happen if the call is made handling an application event.

Will delete this if it turns out to be something really daft on my part.

4
  • I'm almost certain it's a daft move. We all do those from time to time in Lightning. 😅
    – sfdcfox
    Feb 23 '18 at 17:30
  • @sfdcfox Yep. Though I've refined the failing case - see the edited PS.
    – Keith C
    Feb 23 '18 at 17:36
  • 1
    Can you add the code you use to call the aura:method from the working and failing scenarios? Could be something there.
    – Charles T
    Feb 24 '18 at 2:42
  • 1
    please share the application event code - where you trigger the method Feb 25 '18 at 9:06
1

As commenters have suggested, the cause is other code of mine where the component enqueuing the action is getting (very promptly) destroyed before the callback can complete because the component is being replaced by a different one in the body of the parent. Makes sense: just makes my life a bit harder...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.