Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SalesforceBobLightning/370b33cd8339ea34348888128420609e to your computer and use it in GitHub Desktop.
Save SalesforceBobLightning/370b33cd8339ea34348888128420609e to your computer and use it in GitHub Desktop.
Salesforce Lightning JavaScript Method calling Apex Controller Method
exampleJavaScriptMethod : function(cmp, value1, value2) {
var action = cmp.get("c.exampleApexControllerMethod");
action.setParams({'param1': value1, 'param2': value2 });
action.setCallback(this, function(response) {
var state = response.getState();
console.log('exampleJavaScriptMethod state: ' + state);
if(cmp.isValid() && state === "SUCCESS"){
var result = response.getReturnValue();
console.log(result);
// do something
} else if (state === "ERROR"){
var errors = response.getError();
if (errors)
{
if (errors[0] && errors[0].message) {
console.log(errors[0].message);
}
}
}
});
$A.getCallback(function() {
$A.enqueueAction(action);
})();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment