Problem

An education business uses Salesforce to efficiently track student details. Each study center is organized as a business account in Salesforce, and each teacher is stored as a contact within the system. However, the business is facing challenges in managing duplicate contacts , as teachers often work for multiple centers.


To resolve this, they plan to use Salesforce's Account-Contact Relationship feature for deduplication. This way, only one contact record is created for each teacher, but the contact can be linked to multiple study centers.


To achieve this, the business needs to identify duplicate contact records in the system. The criteria for identifying duplicates are based on the combination of first name, last name, and email address.


The Salesforce team has decided to implement an apex method to find the duplicate contacts by concatenating the first name, last name, and email to create a unique identifier. The apex method should return a map , where the key is the unique identifier, and the value is the list of contact records.


Complete the given apex method to fullfill this requirements.


Instructions:


1. The apex method should accept a list of contacts.


2. Concatenate the first name, last name, and email to create a unique key.


3. Add the unique key to the map with the value set to the list of matching contact records.


3. Return the map.


Example:


Duplicate contacts

Id First name Last name Email
003J2007h0UlIAI John Smith John@decodeforce.com
003J2007h0UlIBI John Smith John@decodeforce.com

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

Map<String, List<Contact>> dedupeMap = ContactManager.dedupeRecords(allContacts);

Result - The map will contains

{'johnsmithjohnsmith@decodeforce.com' => [{"Id":"003J2007h0UlIAI", "firstname":"John",...}, {"Id":"003J2007h0UlIBI", "firstname":"John",...}]}


Hint:

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


Click here to view all apex map practice examples.