0

I have a lightning component which is calling server-side apex code. Thes server-side code gets executed properly but setCallBack() function is not getting executed.

<aura:component implements="force:lightningQuickActionWithoutHeader, force:hasRecordId" controller = "serverController" >
<lightning:button variant="brand" label="Yes" title="Yes" onclick="{! c.overwriteData }"/>
</aura:component>

controller

overwriteData: function(component, event, helper) {

    var action = component.get("c.renew");

    action.setParams({
        "RecordId" : component.get("v.recordId")
    });

    action.setCallback(this, function(response) {
       console.log("Response -- " + response.getReturnValue());          
   });
   // Send action off to be executed
   $A.enqueueAction(action);

    helper.closeDialogue();
}

One thing I have noticed that the apex function gets executed after controller function execution complete (I checked developer console for that) and the console log or alert in set callback also do not get executed.

2
  • The helper.close dialogue should be within the call back if you want that to get executed after server response comes back
    – RedDevil
    Commented Nov 23, 2018 at 6:14
  • @RedDevil It works. Thanks! Commented Nov 26, 2018 at 10:45

2 Answers 2

1

@redDevil's Comment on the question answered it:

The helper.close dialogue should be within the call back if you want that to get executed after server response comes back.

0

Instead of just directly checking console.log value, check status as well of response like below -

        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                //alert('recod got' +response.getReturnValue());
            } else if (state === 'INCOMPLETE') {
                console.log('You are offline.');    
            } else if (state === 'ERROR') {
                console.log('other error');
            }
        });

You must log in to answer this question.

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