Skip to content

Instantly share code, notes, and snippets.

@msrivastav13
Last active November 21, 2016 04:51
Show Gist options
  • Save msrivastav13/4830cf7e302d378db8af41a9be957c9b to your computer and use it in GitHub Desktop.
Save msrivastav13/4830cf7e302d378db8af41a9be957c9b to your computer and use it in GitHub Desktop.
Fetching Contacts Via Lightning Component
<aura:component controller="FetchContacts" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
<aura:handler name="init" value="{!this}" action="{!c.fetchContactList}"/>
<aura:attribute name="contacts" type="Contact[]"/>
<aura:iteration items="{!v.contacts}" var="contact">
<div class="card card-body" >
<ui:outputText aura:id="conId" value="{!contact.name}"/>
</div>
</aura:iteration>
</aura:component>
({
fetchContactList : function(component, event, helper) {
var action = component.get("c.getContacts");
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.contacts", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
public class FetchContacts {
@AuraEnabled
public static List<Contact> getContacts() {
return [Select Id, Name, Email, Title, Phone From Contact];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment