// Calling a server-side action ({ callServerSideAction : function(cmp) { // 1. Retrieve an action object by specifying the // Apex method that will be called let action = cmp.get("c.myApexEndpoint"); // 2. Optionally set some action parameters action.setParams({ firstName : cmp.get("v.firstName") }); // 3. Configure a callback function that will be // executed to handle the server response action.setCallback(this, function(response) { // Some response processing code var state = response.getState(); if (state === "SUCCESS") { // Alert the user with the value returned // from the server alert("From server: " + response.getReturnValue()); // You would typically fire a event here to trigger // client-side notification that the server-side // action is complete } else if (state === "INCOMPLETE") { // do something } else if (state === "ERROR") { var errors = response.getError(); if (errors) { if (errors[0] && errors[0].message) { console.log("Error message: " + errors[0].message); } } else { console.log("Unknown error"); } } }); // 4. Optionally set some action configuration flags // 5. Enqueue the action so that the framework processes it $A.enqueueAction(action); } })
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter