You need to sign in to do that
Don't have an account?
prasanth sfdc
Display Accounts with Contacts in lightning component.
Hi,
I want to display list of accounts with contacts in lightning page. Here the code i have written. Here accounts are displaying but contacts are not display. Please help me to display the accounts with contacts.
Thank you.
I want to display list of accounts with contacts in lightning page. Here the code i have written. Here accounts are displaying but contacts are not display. Please help me to display the accounts with contacts.
Thank you.
<aura:component controller="accountsWithContactsClass" implements="flexipage:availableForAllPageTypes" access="global"> <aura:attribute name="accounts" type="Account[]" /> <ui:button label="click this" press="{!c.myAction}" /> <table> <tr><td><b>Name</b></td><td><b>Industry</b></td></tr> <aura:iteration items="{!v.accounts}" var="accs1" > <tr> <td> {!accs1.Name} </td> <td> {!accs1.Industry} </td> <!-- <td> {!accs1.Contacts.lastName} </td> --> </tr> <tr> <aura:iteration items="{!v.accs1.contacts}" var="con1" > <td>{!con1.lastName} </td> </aura:iteration></tr> </aura:iteration> </table> </aura:component> ({ myAction : function(component, event, helper) { var action =component.get("c.getAllAccounts"); console.log('The action value is: '+action); action.setCallback(this, function(a){ component.set("v.accounts", a.getReturnValue()); // console.log('The accs are :'+JSON.stringify(a.getReturnValue())); console.log('The accs are :'+JSON.stringify(a.getReturnValue())); }); $A.enqueueAction(action); } }) public class accountsWithContactsClass { @auraEnabled public static list<account> getAllAccounts() { list<account> accs =[select id,name,phone,industry,(select lastName from contacts) from account limit 10]; // list<account> accs =[select id,name,phone,industry from account limit 10]; // return [select Id,Name from account limit 10]; return accs; } }
Try this code for your component:
<pre><aura:component controller="accountsWithContactsClass" implements="flexipage:availableForAllPageTypes" access="global">
<aura:handler name="init" value="{!this}" action="{!c.myAction}"/>
<aura:attribute name="accounts" type="Account[]" />
<table>
<tr>
<td>
<b>Name</b>
</td>
<td>
<b>Industry</b>
</td>
<td>
<b>Contacts</b>
</td>
</tr>
<aura:iteration items="{!v.accounts}" var="accs1" >
<tr>
<td> {!accs1.Name} </td>
<td> {!accs1.Industry} </td>
<!-- <td> {!accs1.Contacts.lastName} </td> -->
<table>
<aura:iteration items="{!accs1.Contacts}" var="con1" >
<tr>
<td>{!con1.LastName}</td>
</tr>
</aura:iteration>
</table>
</tr>
</aura:iteration>
</table>
</aura:component></pre>
If it helps, mark it as best answer.
Regards,
Aakanksha Singh
All Answers
Try removing v for aura iteration for contacts.
<aura:iteration items="{!accs1.contacts}" var="con1" >
Regards
Aakanksha
I was facing the similar situation for some other objtect, the key point to remember is Lightning component is case sensitive. I debuged your code myself, there is a minor change
<pre>
<aura:iteration items="{!accs1.Contacts}" var="con1" >
</pre>
and
<td>{!con1.LastName}</td>
Try it, you will definitely get result. :)
Mark it as best answer, if your problem is solved.
Regards
Aakanksha Singh
Try this code for your component:
<pre><aura:component controller="accountsWithContactsClass" implements="flexipage:availableForAllPageTypes" access="global">
<aura:handler name="init" value="{!this}" action="{!c.myAction}"/>
<aura:attribute name="accounts" type="Account[]" />
<table>
<tr>
<td>
<b>Name</b>
</td>
<td>
<b>Industry</b>
</td>
<td>
<b>Contacts</b>
</td>
</tr>
<aura:iteration items="{!v.accounts}" var="accs1" >
<tr>
<td> {!accs1.Name} </td>
<td> {!accs1.Industry} </td>
<!-- <td> {!accs1.Contacts.lastName} </td> -->
<table>
<aura:iteration items="{!accs1.Contacts}" var="con1" >
<tr>
<td>{!con1.LastName}</td>
</tr>
</aura:iteration>
</table>
</tr>
</aura:iteration>
</table>
</aura:component></pre>
If it helps, mark it as best answer.
Regards,
Aakanksha Singh
But i need
Name Industry
Contacts 1.
Contacts 2.
Contacts 3.
Thank you.
You can use the below code, but it will not work in myapp.app. Hope it helps.
Regards
Aakanksha Singh
Thank you for sharing the code. Please let me know if any one have this with inline edit also with all fields in lightning.
Display Accounts Record Using Lightning Component (http://www.salesforceadda.com/2017/08/display-accounts-record-using-lightning.html)
Hi all
I have an parent component which displays 10 accounts in my org in a table format with the ids. I made an hyperlink to my account name when i click on that account related contact records a need to be displayed in my child component. i want to send the account id to controller individually through aura iteration how can i send this id to my controller.js remaiining i will do.
Please refer to the blog link mentioned below:
https://wedgecommerce.com/massdelete-lightning-component/
I think you might get your answer
Regards
Aakanksha Singh
As per your responce link it will pass the id to controller from inputCheckbox i want to pass the id on achor tag like the sample code
When i clicked on the Account name i want to pass the value of that rows account id to controller passid. how can i do that please help out i dont want pass array of account ids to controller.
Regards
Naveen Poojary
You can try this: You can refer to these links as well, it might help:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/lightning_base_events.htm
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_which_button_pressed.htm
Regards
Aakanksha Singh
Regards
Naveen Poojary
Please post your total code..
i have same requirement to display contacts when click on account name
Related Contacts should display in Table format
Sorry for the delayed reply
This is the code i used for the requirement .
Thank you. This code is working fine
Application :
<aura:application extends="force:slds" controller="accountsWthContactClass">
<aura:attribute name="accounts" type="Account[]" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<lightning:select label="Accounts" name="Op" aura:id="Op" onchange="{!c.handleAccountChange}" >
<aura:iteration items="{!v.accounts}" var="account">
<option value="{!account.Id}">{!account.Name}</option>
</aura:iteration>
</lightning:select>
<aura:attribute name="contacts" type="contact[]"/>
<aura:attribute name="isOpen" type="boolean" default="false"/>
<div class="slds-m-around--xx-large">
<div class="slds-modal__header">
Related Contacts
</div>
<div class="slds-modal__content slds-p-around_medium" >
<table class="slds-table slds-table_bordered slds-table_cell-buffer" >
<tr class="slds-text-title_caps">
<td>FirstName</td>
<td>Email</td>
<td>Phone</td>
<td>CreatedDate</td>
</tr>
<aura:iteration items="{!v.contacts}" var="cons" >
<tr>
<td> {!cons.FirstName} </td>
<td> {!cons.Email} </td>
<td> {!cons.Phone} </td>
<td> {!cons.CreatedDate}</td></tr>
</aura:iteration>
</table>
</div>
</div>
</aura:application>
Controller:
({
doInit: function(component, event, helper) {
var action = component.get("c.getAllAccounts");
action.setCallback(this, function(result){
var accounts = result.getReturnValue();
console.log(accounts);
component.set("v.accounts",accounts);
window.setTimeout(
$A.getCallback( function() {
component.find("Op").set("v.value", accounts[4].Id);
}));
});
$A.enqueueAction(action);
},
handleAccountChange : function(component, event, helper) {
var accId = event.getSource().get("v.value");
var action = component.get("c.getAllContacts");
action.setParams({
"ParentId": accId
});
action.setCallback(this, function(response){
var state = response.getState();
if (component.isValid() && state === "SUCCESS"){
component.set("v.contacts", response.getReturnValue());
}
else {
console.log("Failed with state" + state);
}
})
$A.enqueueAction(action);
component.set("v.isOpen", true);
},
Close: function(component, event, helper) {
component.set("v.isOpen", false);
},
});
https://www.lightningdesignsystem.com/utilities/grid/
Without using "Static " keyword in method,How to display all contacts in lightning page
Thanks
Raviteja P
Display Related contacts when we click on Account record using Lightning component
http://salesforcecodes.com/display-related-contacts-when-we-click-on-account-record-using-lightning-component/ (http://salesforcecodes.com/display-related-contacts-when-we-click-on-account-record-using-lightning-component/" target="_blank)
Thank you for the sampe code, that's helped me a lot.....
My requirement is to diplay contact when clicking on Account Name instead of Id....
I have tried to achieved but unable to do...Please help me with this