function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nagaraju Mogili 31Nagaraju Mogili 31 

how to display the list of opportunities using lightning component .. help me where am I going wrong

Here is my code,  I was not able to find the error ..
====================================
component :
<aura:component controller = "opplist">
    <aura:attribute name="opportunities" type="list"/>
    <aura:handler name="init" value="doinit" action="{!v.doinit}"/>
    <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
        <thead>
          <tr class="slds-text-heading--label">
            <th scope="col"><div class="slds-truncate" title="ID">ID</div></th>
            <th scope="col"><div class="slds-truncate" title="Name">AccountId</div></th>
            <th scope="col"><div class="slds-truncate" title="Type">probability</div></th>
            <th scope="col"><div class="slds-truncate" title="Number Of Employees">stageName</div></th>
            <th scope="col"><div class="slds-truncate" title="Ticker Symbol">Close Date</div></th>
            <th scope="col"><div class="slds-truncate" title="Phone">Opportunity Currency</div></th>
            <th scope="col"><div class="slds-truncate" title="Delete">Amount</div></th>
          </tr>
        </thead>
        <tbody>
            <aura:iteration items="{!v.opportunities}" var ="x">
                <tr>
          <th scope="row"><div class="slds-truncate" title="{!account.Id}">{!x.Id}</div></th>
          <td><div class="slds-truncate" title="{!account.Name}">{!x.AccountId}</div></td>
          <td><div class="slds-truncate" title="{!account.Type}">{!x.probability}</div></td>
          <td><div class="slds-truncate" title="{!account.NumberOfEmployees}">{!x.stageName}</div></td>
          <td><div class="slds-truncate" title="{!account.NumberOfEmployees}">{!x.closeDate}</div></td>
          <td><div class="slds-truncate" title="{!account.TickerSymbol}">{!x.OpportunityCurrency}</div></td>
          <td><div class="slds-truncate" title="{!account.Phone}">{!x.Amount}</div></td>
                </tr>
           </aura:iteration>                            
        </tbody>
    </table>
</aura:component>
===============================================
controller :
public class opplist {
   
    @AuraEnabled
    public static list<opportunity> getopplist(){
        
        list<opportunity> opps = new list<opportunity>([select Id,AccountId,probability,stageName from opportunity]);
        return opps;
    }
}
===========================
Helper controller :

({
    getopplist : function(component) {
         var action = component.get("v.getopplist");
        
        var self = this;
        action.setCallback(this, function(actionResult) {
            
            component.set('v.getopplist', actionResult.getReturnValue());
         });
          $A.enqueueAction(action);
    }
})

================================================
component controller

({
    doinit : function(component, event, helper) {
        helper.getAccountlist(component);
    }
})

 
Ashish KumarAshish Kumar
Hi Nagaraju,

Please try below code.
 
====================================
component :
<aura:component controller = "opplist">
    <aura:attribute name="opportunities" type="list"/>
    <aura:handler name="init" value="doinit" action="{!v.doinit}"/>
    <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
        <thead>
          <tr class="slds-text-heading--label">
            <th scope="col"><div class="slds-truncate" title="ID">ID</div></th>
            <th scope="col"><div class="slds-truncate" title="Name">AccountId</div></th>
            <th scope="col"><div class="slds-truncate" title="Type">probability</div></th>
            <th scope="col"><div class="slds-truncate" title="Number Of Employees">stageName</div></th>
            <th scope="col"><div class="slds-truncate" title="Ticker Symbol">Close Date</div></th>
            <th scope="col"><div class="slds-truncate" title="Phone">Opportunity Currency</div></th>
            <th scope="col"><div class="slds-truncate" title="Delete">Amount</div></th>
          </tr>
        </thead>
        <tbody>
            <aura:iteration items="{!v.opportunities}" var ="x">
                <tr>
          <th scope="row"><div class="slds-truncate" title="{!account.Id}">{!x.Id}</div></th>
          <td><div class="slds-truncate" title="">{!x.AccountId}</div></td>
          <td><div class="slds-truncate" title="">{!x.probability}</div></td>
          <td><div class="slds-truncate" title="">{!x.stageName}</div></td>
          <td><div class="slds-truncate" title="">{!x.closeDate}</div></td>
          <td><div class="slds-truncate" title="">{!x.OpportunityCurrency}</div></td>
          <td><div class="slds-truncate" title="">{!x.Amount}</div></td>
                </tr>
           </aura:iteration>                            
        </tbody>
    </table>
</aura:component>
===============================================
controller :
public class opplist {
   
    @AuraEnabled
    public static list<opportunity> getopplist(){
        
        list<opportunity> opps = new list<opportunity>([select Id,AccountId,probability,stageName from opportunity]);
        return opps;
    }
}
===========================
Helper controller :

({
    getopplistFunction : function(component) {
         var action = component.get("c.getopplist"); // replace v by "c" - c is the value //provider which enables you to wire up event handlers and actions for the component
        
        var self = this;
        action.setCallback(this, function(actionResult) {
            
            component.set('v.opportunities', actionResult.getReturnValue());
         });
          $A.enqueueAction(action);
    }
})

================================================
component controller

({
    doinit : function(component, event, helper) {
        helper.getopplistFunction(component);
    }
})


Hope this helps,

Regards,
Ashish Kr.
Deepak Kumar SharmaDeepak Kumar Sharma
Hi NagaRaju,
please try the soltion given below :- 
Component:-
..................................................................
<aura:component controller = "opplist">
    <aura:attribute name="opportunities" type="list"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doinit}"/>
    <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
        <thead>
            <tr class="slds-text-heading--label">
                <th scope="col"><div class="slds-truncate" title="ID">ID</div></th>
                <th scope="col"><div class="slds-truncate" title="Name">AccountId</div></th>
                <th scope="col"><div class="slds-truncate" title="Type">probability</div></th>
                <th scope="col"><div class="slds-truncate" title="Number Of Employees">stageName</div></th>
                <th scope="col"><div class="slds-truncate" title="Ticker Symbol">Close Date</div></th>
                <th scope="col"><div class="slds-truncate" title="Phone">Opportunity Currency</div></th>
                <th scope="col"><div class="slds-truncate" title="Delete">Amount</div></th>
            </tr>
        </thead>
        <tbody>
            <aura:iteration items="{!v.opportunities}" var ="x">
                <tr>
                    <th scope="row"><div class="slds-truncate" title="{!x.Id}">{!x.Id}</div></th>
                    <td><div class="slds-truncate" title="{!x.AccountId}">{!x.AccountId}</div></td>
                    <td><div class="slds-truncate" title="{!x.Type}">{!x.Probability}</div></td>
                    <td><div class="slds-truncate" title="{!x.NumberOfEmployees}">{!x.StageName}</div></td>
                    <td><div class="slds-truncate" title="{!x.NumberOfEmployees}">{!x.CloseDate}</div></td>
                    <td><div class="slds-truncate" title="{!x.TickerSymbol}">{!x.OpportunityCurrency}</div></td>
                    <td><div class="slds-truncate" title="{!x.Phone}">{!x.Amount}</div></td>
                </tr>
            </aura:iteration>                            
        </tbody>
    </table>
</aura:component>
...................................................................................
Controller:-
...................................................................................
({
    doinit : function(component, event, helper) {
        helper.getAccountlist(component);
    }
})
....................................................................................
Controller Helper:-
....................................................................................

({
    getAccountlist : function(component) {
        var action = component.get("c.getopplist");
        var self = this;
        action.setCallback(this, function(actionResult) {
            component.set('v.opportunities', actionResult.getReturnValue());
         });
          $A.enqueueAction(action);
    }
})
...................................................................................
Server side controller:-
...................................................................................
public class opplist {
   
    @AuraEnabled
    public static list<opportunity> getopplist(){
        
        list<opportunity> opps = new list<opportunity>([select Id,AccountId,probability,stageName from opportunity]);
        return opps;
    }
}

Thanks,
Happy Coding :)