You need to sign in to do that
Don't have an account?
Qiuyan LIU
Can't get the return value of apex function In lightning component controller
Hello everyone,
In a Lightning component, I am trying to call Apex function and get a String return value,
The function I called in Apex :
public with sharing class UserSearch {
....
@AuraEnabled
public static String createPersonAccount(Account account) {
System.debug('createPersonAccount Function begins...');
return 'Test !';
}
...
}
in the comononent controller :
var account = component.get("v.account");
var action = component.get("c.createPersonAccount");
action.setParams({
'account' : account
});
action.setCallback(this, function(actionResult) {
var returnValue = actionResult.getReturnValue();
});
$A.enqueueAction(action);
With the same code, sometimes I can get the return value correctly, but most of the time, what I get is like this :
Sorry the photo is not very clear,
the message are :
error: Array[1]
0: Object
message: "Disconnected or Canceled"
__proto__: Object
length: 1
__proto__: Array[0]
id: "158;a"
returnValue: undefined
state: "INCOMPLETE"
__proto__: Action
Could any one help me please ?
In a Lightning component, I am trying to call Apex function and get a String return value,
The function I called in Apex :
public with sharing class UserSearch {
....
@AuraEnabled
public static String createPersonAccount(Account account) {
System.debug('createPersonAccount Function begins...');
return 'Test !';
}
...
}
in the comononent controller :
var account = component.get("v.account");
var action = component.get("c.createPersonAccount");
action.setParams({
'account' : account
});
action.setCallback(this, function(actionResult) {
var returnValue = actionResult.getReturnValue();
});
$A.enqueueAction(action);
With the same code, sometimes I can get the return value correctly, but most of the time, what I get is like this :
Sorry the photo is not very clear,
the message are :
error: Array[1]
0: Object
message: "Disconnected or Canceled"
__proto__: Object
length: 1
__proto__: Array[0]
id: "158;a"
returnValue: undefined
state: "INCOMPLETE"
__proto__: Action
Could any one help me please ?
The v.account is an component attribute, it is defined like this :
<aura:attribute name="account" type="Account" default="{ sobjectType: 'Account' }"/>
I tried to serialized before sending the return value, nothing changed, I also tried just return a simple String like 'Test' . It is always the same, sometimes I can get the return value, most of the time I CAN NOT. It is kinda weird for me !