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 Nov 23 '18 at 6:14
  • @RedDevil It works. Thanks! – Harinder Jakhar Nov 26 '18 at 10:45
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');
            }
        });

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.