Last active
December 28, 2018 21:58
-
-
Save tsmalara/c9c20e0f60c99e41c4072e37eff4f2df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component, event, helper) { | |
// create a one-time use instance of the getAccount action | |
// in the server-side controller | |
var action = component.get("c.getAccount"); | |
action.setParams({ | |
"accountId": component.get("v.recordId") | |
}); | |
// Create a callback that is executed after | |
// the server-side action returns | |
action.setCallback(this, function(response) { | |
var state = response.getState(); | |
if (component.isValid() && state === "SUCCESS") { | |
//Set the component account attribute to the returned account object | |
component.set("v.account", response.getReturnValue()); | |
} | |
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"); | |
} | |
} | |
}); | |
// $A.enqueueAction adds the server-side action to the queue. | |
$A.enqueueAction(action); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment