You need to sign in to do that
Don't have an account?
Vinay_gupta
Map Filling inside For Loop
Hi All,
I am net to Map and need ur help here.
Can anyone help me how to fill value in Map in below example. Can you please help me with the Code?
Map<id,List<Contacts>> CustMap = new Map<Id,List<Contacts>>;
for(Account ac:[SELECT id,name,(SELECT id FROM Contacts) FROM Account])
{
How to fill Map here where Id would be Account Id and Values would be list of Contacts.?
}
Regards,
Varun
I am net to Map and need ur help here.
Can anyone help me how to fill value in Map in below example. Can you please help me with the Code?
Map<id,List<Contacts>> CustMap = new Map<Id,List<Contacts>>;
for(Account ac:[SELECT id,name,(SELECT id FROM Contacts) FROM Account])
{
How to fill Map here where Id would be Account Id and Values would be list of Contacts.?
}
Regards,
Varun
Let us know if this will help you
All Answers
Try this one.
Map<id,List<Contact>> CustMap = new Map<Id,List<Contact>>();
for(Account ac:[SELECT id,name,(SELECT id FROM Contacts) FROM Account limit 5])
{
CustMap.put(ac.Id, ac.contacts);
}
Hi Varun,
Please try this hope it will help you.
Mark as a best if it help you.
Regards,
Ajay
Let us know if this will help you