+ Start a Discussion
MJRMJR 

Displaying only contacts from display

List<Account>Acl = new List<Account>([Select Id,name 

from Account limit 10 ]);

 Map <Id,Account> mpn = new map<Id,Account>();

 for (Account a : acl)
 { mpn.put(a.Id,a);
 }
 system.debug(mpn.get('0019000000PDZvkAAH')); and i should not cal the contact through dot operator ie (mpn.get('0019000000PDZvkAAH').contacts)

 can any one suggest any idea

 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

Change the code lil bit

 

List < Account > Acl = new List < Account > ([Select Id, name,(SELECT Id FROM Contacts) from Account limit 10]);

Map < Id, List<Contact> > mpn = new map < Id, List<Contact> > ();

for (Account a: acl) {
    mpn.put(a.Id, a.Contacts);
}

 You can access the contacts related to an account using the Id .

 

You can access related contacts by List<Contacts> cons = mpn.get('AccountId');

All Answers

Yoganand GadekarYoganand Gadekar

Please elaborate on your requirement. Post more details.

Avidev9Avidev9

Change the code lil bit

 

List < Account > Acl = new List < Account > ([Select Id, name,(SELECT Id FROM Contacts) from Account limit 10]);

Map < Id, List<Contact> > mpn = new map < Id, List<Contact> > ();

for (Account a: acl) {
    mpn.put(a.Id, a.Contacts);
}

 You can access the contacts related to an account using the Id .

 

You can access related contacts by List<Contacts> cons = mpn.get('AccountId');

This was selected as the best answer
MJRMJR

thank u