Skip to content

Instantly share code, notes, and snippets.

@xgeek-net
Created January 6, 2019 07:24
Show Gist options
  • Save xgeek-net/d6e487e751ad2331bea2a462f152633b to your computer and use it in GitHub Desktop.
Save xgeek-net/d6e487e751ad2331bea2a462f152633b to your computer and use it in GitHub Desktop.
SampleAuraHelper.js Lightning Component
({
/**
* Call Apex Server-Side method in Promise
*/
sendRequest : function(cmp, methodName, params){
return new Promise($A.getCallback(function(resolve, reject) {
var action = cmp.get(methodName);
action.setParams(params);
action.setCallback(self, function(res) {
var state = res.getState();
if(state === 'SUCCESS') {
resolve(res.getReturnValue());
} else if(state === 'ERROR') {
reject(action.getError())
}
});
$A.enqueueAction(action);
}));
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment