diff --git a/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCase.md b/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCase.md index e7923c4..a5cd482 100644 --- a/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCase.md +++ b/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCase.md @@ -31,7 +31,7 @@ System.debug(normalizedEmail); // Outputs: 'contact@example.com' --- ### Challenge: Using `toLowerCase()` for Email Deduplication -You are tasked with cleaning up a set of email addresses in a Salesforce application. Due to various input methods and user errors, the set might contain emails with different case formats. Using `toLowerCase()`, you can standardize all email addresses to lowercase. +You are tasked with cleaning up a list of email addresses in a Salesforce application. Due to various input methods and user errors, the list might contain duplicate emails with different case formats. Using `toLowerCase()`, you can standardize all email addresses to lowercase to help identify and remove duplicates. **Your task:** -Write code that processes a set of email strings and converts each to lowercase. +Write code that processes a list of email strings, converts each to lowercase, and then deduplicates the list. You will start with a predefined list of emails that includes potential duplicates with varying cases. Your method should return a set of strings. \ No newline at end of file diff --git a/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseSolution.cls b/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseSolution.cls index 34c0fce..abe7433 100644 --- a/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseSolution.cls +++ b/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseSolution.cls @@ -1,8 +1,9 @@ -public class ToLowerCaseSolution { - public Set standardizeEmails(Set emails) { +public class StringUtils { + public Set standardizeEmails(List emails) { + Set uniqueEmails = new Set(); for (String email : emails) { - email.toLowerCase(); + uniqueEmails.add(email.toLowerCase()); } - return emails; + return uniqueEmails; } -} +} \ No newline at end of file diff --git a/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseTest.cls b/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseTest.cls index dbecaea..46d785d 100644 --- a/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseTest.cls +++ b/force-app/main/default/apexdeepdive/string/toLowerCase/ToLowerCaseTest.cls @@ -28,10 +28,11 @@ public with sharing class ToLowerCaseTest { } public TestResult test1(String testNum) { - Set emailsInput = new Set{ + List emailsInput = new List{ 'test@email.com', 'WarRen@cloudcodeacademy.COM', - 'maRc@SaleFORCE.com' + 'maRc@SaleFORCE.com', + 'MARC@SALESFORCE.COM' }; String testDesc = formatEmailSet(emailsInput); @@ -45,7 +46,7 @@ public with sharing class ToLowerCaseTest { try { Set result = su.standardizeEmails(emailsInput); - if(!emailsSolution.containsAll(result)){ + if(result == null || !emailsSolution.containsAll(result)){ msg = 'Expected ' + emailsSolution + @@ -60,7 +61,7 @@ public with sharing class ToLowerCaseTest { } public TestResult test2(String testNum) { - Set emailsInput = new Set{ + List emailsInput = new List{ 'PARKER@SALESFORCE.COM', 'Another@emaiL.CoM', '123Test@TeStER.com' @@ -76,7 +77,7 @@ public with sharing class ToLowerCaseTest { try { Set result = su.standardizeEmails(emailsInput); - if(!emailsSolution.containsAll(result)){ + if(result == null || !emailsSolution.containsAll(result)){ msg = 'Expected ' + emailsSolution +