Problem

A global company is developing a website for their business managers that operates outside of Salesforce. This business portal is designed to allow managers to view their clients(accounts) and related contacts, providing them with access to client details online.


The Salesforce team has already created an SOQL query that finds the list of business contacts associated with a specific business manager. However, the external portal requires a detailed mapping of accounts and their respective contacts to display this information effectively on the website.


To meet this requirement, the Salesforce team has decided to develop an apex method. This method will generate a map of account id's and their corresponding contacts. The external portal can then use this map to display client information seamlessly.


Complete the given apex code to fulfill these requirements.


Instructions:


1. The apex method must accept a list of contacts as its input.


2. Implement an apex method that returns a map, where the key is the account id, and the value is a list of Contact records.


3. Ensure the method returns the map of account ids and their related contacts.



Example:


//Assume the contact list has ( {lastname = 'Dome', accountId="0012xxxx"}, {lastname = 'John', accountId="0012xxxx"})

Map accountContactMap = ManageAccountController.getAccountsAndContacts(list<Contact>);

//The accountContactMap will have following values
0012xxxx -> ({lastname = 'Dome', accountId="0012xxxx"}, {lastname = 'John', accountId="0012xxxx"})


Hint:

Use the apex map methods to map the key value pairs in apex


Click here to view all apex map practice examples.