0
votes

I am creating a salesforce lightning component to list the leads of the current logged in user.

I have managed to write the following code, but when i add the component to the page, and preview it, I dont see any leads.

<aura:component implements="forceCommunity:availableForAllPageTypes" access="global" >
 <div class="slds"> 

<table class="slds-table slds-table--bordered slds-table--striped">
    <thead>
        <tr>
            <th scope="col"><span class="slds-truncate">Company</span></th>
            <th scope="col"><span class="slds-truncate">Annual Revenue</span></th>
        </tr>
    </thead>
    <tbody>
        <aura:iteration items="{!v.leads}" var="lead">
            <tr>
                <td>{!lead.Company}</td>
                <td>{!lead.AnnualRevenue}</td>
            </tr>
        </aura:iteration>
    </tbody>
</table>
    </div>

It will be great, if someone could tell me what is that I am doing wrong. Thank you

2
You would appear to be doing a lot wrong - where is your controller, your attributes? Work your way through this: trailhead.salesforce.com/en/module/lex_dev_lc_basicsCaspar Harmer

2 Answers

1
votes

You can follow the tutorial for Displaying a Contact List and replace the Logic with that for Leads

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_one_demo_load.htm

0
votes

This might be because

  1. You have not added a controller on your lightning component.

    <aura:component implements="forceCommunity:availableForAllPageTypes" controller="ContactController" access="global" >
    
  2. You have not declared the attribute "leads" which you have used in the iteration.

    <aura:attribute name="leads" type="Lead[]"/>
    
  3. You have not set the "leads" attribute which you fetched from the Apex controller.

    controller.set("v.leads", variableWithLeadsList);
    
  4. You have not fetched data from the Apex controller. In this case, as mentioned by Rajdeep Dua, https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_one_demo_load.htm link explains the whole process and will help you if you replace Contact with Lead.