You need to sign in to do that
Don't have an account?
Can we have action.setCallback() inside another action.setCallBack()??
Hi,
Can we have action.setCallback() inside another action.setCallBack()??
My code goes like this:
controller.js
doInit : function(cmp,event,helper){
//call apex server method1
action1.setCallBack(this,function(response){
console.log('INSIDE action1');
if(state == "SUCCESS"){
//call apex server method2
action2.setCallBack(this,function(resp){
console.log('INSIDE action2');
});
}
});
}
On executing this code, 'INSIDE action1' is getting logged whereas 'INSIDE action2' is not getting logged. But apex method2 is getting invoked and both the apex methods works fine.
Can we have an action.setCallback() inside another action.setCallback()??
Thanks,
Mythili
Thanks for the code.
Please do some DML operation in message2 function and then check action2.setCallback. It is not getting executed.
I did some research around it and found that it breaks in the following scenario:
When I call e.force:closeQuickAction in js controller to close the white screen that pops up as soon the button is clicked. I am doing this because I do not want the white screen to be displayed. I just want some function to take place at the backgroud.
If $A.get("e.force:closeQuickAction").fire(); had not been there in the code, then both the action.setCallback() gets fired.
I am posting my code here:
<aura:component controller="demoCls" implements="force:lightningQuickActionWithoutHeader">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>
({
doInit: function (cmp, event) {
var action = cmp.get("c.message11");
action.setCallback(this, function(response) {
$A.get("e.force:closeQuickAction").fire();
var state = response.getState();
if (state === "SUCCESS") {
console.log(response.getReturnValue());
var action2 = cmp.get("c.message22");
action2.setParams({
"acc" : response
});
action2.setCallback(this, function(response) {
console.log('dfsdgfsg');
var state = response.getState();
if (state === "SUCCESS") {
}
});
$A.enqueueAction(action2);
}
});
$A.enqueueAction(action);
}
})
public class demoCls {
@Auraenabled
public static Account message11(){
Account acc = [select id,Name from Account where id='0019000000yqP5fAAE'];
return acc;
}
@Auraenabled
public static void message22(Account acc){
update acc;
}
}