I would like to show Accounts and Related Contacts in a Picklist.

public class mappingaccount1 {
  public List<SelectOption> mapcon { get; set; } 
  public List<Contact> mapcon { get; set; } 
  public Map<Account, List<Contact>> mapconn { get; set; } 

  public mappingaccount1(){
    mapconn = new Map<Account, List<Contact>>();
    List<Account> lstacc= [SELECT Id, Name, (SELECT Id, Name FROM Contact) FROM Account];

    for(Account a : lstacc) {
      List<SelectOption> mapcon = [SELECT id,name FROM Contact WHERE AccountId =:a.id];


An org might have 10,000 Accounts and 10,000,000 Contacts. Unless you can guarantee that there will only ever be a few hundred of each object in your target org you should re-think your design.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.