Skip to content

Instantly share code, notes, and snippets.

@keirbowden
Last active January 21, 2016 13:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keirbowden/12aeb7aa62f07132c2a7 to your computer and use it in GitHub Desktop.
Save keirbowden/12aeb7aa62f07132c2a7 to your computer and use it in GitHub Desktop.
Lightning Component Helper for the Lightning Account Wrappers blog post
({
init : function(cmp, ev) {
var action = cmp.get("c.GetAccountNames");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var accs=response.getReturnValue()
var wrappers=new Array();
for (var idx=0; idx<accs.length; idx++) {
var wrapper = { 'acc' : accs[idx],
'selected' : false
};
wrappers.push(wrapper);
}
cmp.set('v.wrappers', wrappers);
}
else if (state === "ERROR") {
alert('Error : ' + JSON.stringify(errors));
}
});
$A.enqueueAction(action);
},
getAccounts : function(cmp, ev) {
var action = cmp.get("c.GetAccountDetails");
var wrappers=cmp.get('v.wrappers');
var ids=new Array();
for (var idx=0; idx<wrappers.length; idx++) {
if (wrappers[idx].selected) {
ids.push(wrappers[idx].acc.Id);
}
}
var idListJSON=JSON.stringify(ids);
action.setParams({
"idListJSONStr": idListJSON
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var accs=response.getReturnValue()
cmp.set('v.accounts', accs);
}
else if (state === "ERROR") {
var errors = response.getError();
alert('Error : ' + JSON.stringify(errors));
}
});
$A.enqueueAction(action);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment