Aura
Call Apex Method using Promise
promiseAction: function (cmp, methodName, params) {
var self = this;
return new Promise(function (resolve, reject) {
var action = cmp.get(methodName);
action.setParams(params);
action.setCallback(this, function (response) {
var state = response.getState();
if (cmp.isValid() && state === 'SUCCESS') {
var result = JSON.parse(response.getReturnValue());
resolve(result);
} else if (state === 'ERROR') {
var errors = response.getError();
self.handleErrors(errors);
reject(errors);
}
});
$A.getCallback(function () {
$A.enqueueAction(action);
})();
});
},Call Apex Method using Callback
Show Toast
Handle Errors
Last updated