0

How to display all lead records with status using lightning component page?

Component:

<aura:component implements="force:appHostable" controller="GetLeadRecords" >
    <aura:attribute name="reg" type="Lead"/>
    <ui:button label="GetLeadRecords" press="{!c.myAction}"/>
    <aura:iteration var="r" items="{!v.reg}" >
    <p>{!r.name}</p>
    <p>{!r.Status}</p>
    </aura:iteration>
</aura:component>

Controller:

({
   myAction : function(component, event, helper) {
        var action = component.get("c.GetLeads");
        action.setCallback(this, function(response){
            var name = response.getState();
            if (name == "") {
                component.set("v.reg", response.getReturnValue());
            }
        });
     $A.enqueueAction(action);
    }
})

Apex Class:

global with sharing class GetLeadRecords {
@auraEnabled
    public static List<Lead> GetLeads()
    {
     List<Lead> reg=new LIST<Lead>();  
        reg=[select id,name,Status from Lead];
        return reg;
    } 
    public Lead getSelectedregistrations(Id id)
    {    
      Lead  reg=[select id,name,Status from Lead where id=:id];
        return reg;
    } 

}
3
  • 2
    Have you tried reading some documentation in order to achieve this? maybe some effort from your part and update your post with any attempts to do so? if you encounter any problems, we are more than happy to help.
    – glls
    Aug 8 '17 at 14:49
  • 1
    thx for updating your post! from what you posted, what doesn't seem to be working, what is the current behavior? do you have any errors?
    – glls
    Aug 8 '17 at 15:19
  • @glls, yeah! showing error. but it could not display lead records, please check and give me what is the mistake on that.
    – user43414
    Aug 9 '17 at 9:15
1
        if (name == "") {

This will never be true, as getState will never return an empty string. See "Calling a Server-Side Action" for more details. Typically, you'll want to check for success:

if(name === "SUCCESS") {

Also, your attribute should be a List:

<aura:attribute name="reg" type="Lead[]" />
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy