I want to show contact related to particular account.Ex. I am having a dropdown having account list, i want to get whole contacts of that account while click on that account
public class AccPicklistConRelatedC {
public String selectedAccId{get;set;}
public List<Contact> ContactNames{get;set;}
public List<SelectOption> getAccountNames() {
List<SelectOption> accOptions= new List<SelectOption>();
accOptions.add( new SelectOption('','--Select--'));
for( Account acc : [SELECT Id, Name FROM Account ] ) {
accOptions.add( new SelectOption(acc.Id,acc.name));
}
return accOptions;
}
public void ShowTable() {
ContactNames = new List<Contact>();
for(Contact cr : [SELECT Id, Name, Phone FROM Contact WHERE AccountId=:selectedAccId]){
ContactNames.add(cr);
}
}
}
I hope it helps you.
Kindly 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. It will help to keep this community clean.
I have created a lightning component according to your requirements. Please try the below code:
Apex:
public class AccPicklistRelatedConC {
@AuraEnabled
public static List<Account> getAccountName() {
List<Account> lstNames = [SELECT Id, Name FROM Account];
return lstNames;
}
@AuraEnabled
public static List<Contact> getConatct(String aName) {
List<Contact> con = [SELECT Id, Name, Phone, Email, Account.Name FROM Contact WHERE Account.Name=:aName];
return con;
}
}
Kindly 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. It will help to keep this community clean.
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
I hope it helps you.
Kindly 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. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
I have created a lightning component according to your requirements. Please try the below code:
Apex:
Component:
Controller:
CSS:
Application:
I hope it helps you.
Kindly 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. It will help to keep this community clean.
Regards,
Khan Anas