Skip to main content
1 answer
  1. Jan 9, 2022, 3:42 PM

    Try this

    List<Contact> contactList = new List<Contact>();

    contactList = [SELECT AccountId,LastName FROM Contact LIMIT 100];

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

    for(Contact cont: contactList)

        {

            if(mapidVsContact.get(cont.AccountId) == NULL)

                 {

                     mapidVsContact.put(cont.AccountId,new List<Contact>());

                 }

                     mapidVsContact.get(cont.AccountId).add(cont);

        }

    system.debug('---mapidVsContact--->'+mapidVsContact);
0/9000