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
Saie Shendage 7Saie Shendage 7 

Display account names in the dropdown list and upon changing account display its respective contacts.

I want to display account names in the form of dropdown list and when I change the account name from the dropdown, I should be able to see data about contacts(associated with the respective account) in the tabular format using cutom controller.
Please help. Thank you in advance.
AnudeepAnudeep (Salesforce Developers) 
A similar requirement has already been discussed here. I recommend taking a look

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
ANUTEJANUTEJ (Salesforce Developers) 
Hi Saie,

Can you try checking the below lightning component implementation:
<aura:component controller=”PaginationController”>
<aura:attribute name=”accounts” type=”account[]” />
<aura:attribute name=”contacts” type=”contact[]” />

<aura:handler name=”init” value=”{!this}” action=”{!c.doInit}”/>

<br />
<table class=”slds-table slds-table_bordered slds-table_cell-buffer”>
<thead>
<tr class=”slds-text-title_caps”>
<th scope=”col”>

Contact Id
</th>
<th scope=”col”>

Contact Name
</th>
</tr>
</thead>
<tbody>
<aura:iteration items=”{!v.contacts}” var=”contact”>
<tr>
<th scope=”row” data-label=”Contact Id”>

{!contact.Id}
</th>
<td data-label=”Contact Name”>

{!contact.Name}
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>

===================================== testCmpController.js ====================================

({
doInit : function(component, event, helper) {
helper.loadAccounts(component);
},

onSelectChange : function(component, event, helper) {
var selected = component.find(“dd1”).get(“v.value”);
//alert(‘selected: ‘ + component.get(‘v.accounts’)[0].Contacts[0].Name);
var abc = component.get(‘v.accounts’);

for(i=0; i<abc.length;i++)
{
if(abc[i].Id == selected)
{
component.set(“v.contacts”, abc[i].Contacts);
//alert(abc[i].Contacts);
}
}

//do something else
}

})

===================================== testCmpHelper.js ====================================================
({
loadAccounts : function(cmp) {
var action = cmp.get(“c.getAccounts”);
action.setCallback(this, function(response) {
var state = response.getState();
if (state === “SUCCESS”) {
cmp.set(“v.accounts”, response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})

====================================== PaginationController.apxc ===========================================
public class PaginationController {

@AuraEnabled
public static List<Account> getAccounts(){
return [select Id, Name, (Select Id, name from contacts) from account where Id IN (‘0012800000Y0H09AAF’, ‘0012800000Y0H0FAAV’, ‘0012800000hBU2qAAG’, ‘0012800000smvlCAAQ’)];
}

}
Reference: https://umangsinghal.wordpress.com/2017/05/23/change-table-value-on-the-basis-of-drop-down-in-lightning/

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Saie Shendage 7Saie Shendage 7
Anudeep I tried the link you sent, but it's not working. Please help if you find something related to my question
 
Saie Shendage 7Saie Shendage 7
Anutej can you please send me vf page and custom controller code. My whole code is using apex and vf, can't change it now