Skip to content

Instantly share code, notes, and snippets.

@Sunil02kumar
Created September 27, 2018 17:21
Show Gist options
  • Select an option

  • Save Sunil02kumar/a6e11ce4b90c0ca21d782ddca7bac311 to your computer and use it in GitHub Desktop.

Select an option

Save Sunil02kumar/a6e11ce4b90c0ca21d782ddca7bac311 to your computer and use it in GitHub Desktop.
<aura:application extends="force:slds">
<!-- extends "force:slds" interface so that SLDS will be imported in lightning component-->
<c:SK_LightningBasicsSSC/>
</aura:application>
<aura:component controller="SK_LightningBasicsSSController">
<aura:attribute name="ltngAccountList" type="List"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<table class="slds-table">
<tr>
<th>Account Name</th>
<th>Account Type</th>
</tr>
<aura:iteration items="{!v.ltngAccountList}" var="Acc">
<tr>
<td>{!Acc.Name}</td>
<td>{!Acc.Type}</td>
</tr>
</aura:iteration>
</table>
</aura:component>
({
doInit : function(component, event, helper) {
var actionName= component.get("c.findRecentAccounts");
actionName.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var apexResponse=response.getReturnValue();
//set response to attribute value
console.log('***'+JSON.stringify(apexResponse));
component.set("v.ltngAccountList",apexResponse);
}else if(state === "ERROR"){
var errors = response.getError();
console.error(errors);
alert('Problem with connection. Contact your system administrator.');
}
});
$A.enqueueAction(actionName);
}
})
Public class SK_LightningBasicsSSController {
@AuraEnabled
public static List<Account> findRecentAccounts(){
return [select id,name,type from Account
order by LastmodifiedDate DESC Limit 10];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment