
3 answers
Hi Suraj,Below Sample Code can fulfill your requirements, Hope this will work for you.Component :<aura:component controller="ShowAccounts" access="global"> <aura:attribute name="AccountList" type="list[]" /> <aura:handler name="init" action="{!c.doInit}" value="{!this}"/> <table class="slds-table slds-table_bordered slds-table_cell-buffer"> <thead> <tr class="slds-text-title_caps"> <th scope="col"> <div class="slds-truncate" title="Account Name">Account Name</div> </th> <th scope="col"> <div class="slds-truncate" title="Contact">Contact</div> </th> <th scope="col"> <div class="slds-truncate" title="Opportunity">Opportunity</div> </th> </tr> </thead> <tbody> <aura:iteration items="{!v.AccountList}" var="acc" > <tr> <td data-label="Account Name"> <div class="slds-truncate" title="Cloudhub">{!acc.Name}</div> </td> <td data-label="Contact"> <ui:inputSelect class="slds-select" aura:id="contactID"> <ui:inputSelectOption text="" label="Please Select a contact" disabled="true" /> <aura:iteration items="{!acc.Contacts}" var="cont"> <ui:inputSelectOption text="{!cont.Id}" label="{!cont.Name}" /> </aura:iteration> </ui:inputSelect> </td> <td data-label="Opportunity"> <ui:inputSelect class="slds-select" aura:id="opportunityID"> <ui:inputSelectOption text="" label="Please Select an Opportunity" disabled="true" /> <aura:iteration items="{!acc.Opportunities}" var="opp"> <ui:inputSelectOption text="{!opp.Id}" label="{!opp.Name}" /> </aura:iteration> </ui:inputSelect> </td> </tr> </aura:iteration> </tbody> </table> </aura:component>controller :({ doInit : function(c, e, h) { h.doInit_Helper(c, e, h); },})Helper :({ doInit_Helper : function(c, e, h) { try { var action = c.get("c.getAllAccounts"); action.setCallback(this, function(response){ var state = response.getState(); if(state === 'SUCCESS'){ var res = response.getReturnValue(); console.log('res-->>>'+res); if(res != null) { c.set("v.AccountList", res); } }else if (state === 'ERROR'){ var errors = response.getError(); if (errors) { if (errors[0] && errors[0].message) { console.log("Error message: " + errors[0].message); } } else { console.log("Unknown error"); } }else{ console.log('Something went wrong, Please check with your admin'); } }); $A.enqueueAction(action); } catch(ex){ console.log(ex); } },})Class :
Please mark this as best answer if this solves your problem.Thank you,Ajay Dubedipublic class ShowAccounts {
@AuraEnabled
public static List<Account> getAllAccounts() {
try{
List<Account> accList = new List<Account>();
accList = [select id, Name,(Select Id, Name from contacts),(Select Id, Name From Opportunities) from Account LIMIT 1000];
if(accList.size() > 0) {
system.debug('accList-->>'+accList);
return accList;
}
} catch(Exception ex) {
system.debug('Exception Error');
}
return null;
}
}