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
Harish PHarish P 

map for account id as key and related contact records are values using for loops....plz implement and send code

GouthamGoutham
Hi,
load map as following
Map<id,list<contact>> accountRelatedContacts = new Map<id,list<contact>>();

for(Account acc : [select id,(select id from contacts) from Account]){
	if(accountRelatedContacts.get(acc.id)==null)
		accountRelatedContacts.put(acc.id,new list<contact>{});
	if(accountRelatedContacts.get(acc.id)!=null)
		accountRelatedContacts.get(acc.id).addAll(acc.contacts);
}