I have this Map Collection with the key of Id and the value is a List of contact. And I have a List of all contact with different Account Id.
Now, what i am trying to work is Upon looping the List of contact the accountId will be the index and add the collection to that index and if the AccountId of the Contact is already in the Map collection it will just add the collection to the specifid index of the map collection, how does it work?
My code:
Map<Id,List<Contact>> accountContactMap = new Map<Id,List<Contact>>();
for(Contact contInsert: contactList){
if(accountContactMap.containsKey(contInsert.AccountId)){
accountContactMap.put(contInsert.AccountId,contInsert);
}
}
And also I am having an error:
Method does not exist or incorrect signature: void (Id, Contact) from the type Map<Id,List<Contact>>
Any help please?