Last active
November 21, 2016 04:51
-
-
Save msrivastav13/4830cf7e302d378db8af41a9be957c9b to your computer and use it in GitHub Desktop.
Fetching Contacts Via Lightning Component
This file contains hidden or 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
<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> |
This file contains hidden or 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
({ | |
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); | |
} | |
}) |
This file contains hidden or 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
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