function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salesforce BeginnerSalesforce Beginner 

How to handle the ignore case in strings

Hello All,

I am using a Map<string,List<string>> mapEmailtoBodyFields = new Map<string,List<string>>(); to map the email ids to description fields of an object.

Requirement : Have to check whether email id is present in our system. if present I have to do some logic. my question is, when I am comparing email in the map with the email ids in the system (our salesforce org), I might run into a case mismatch. For example:

key in the map : John.Doe@xyz.com
Email Id in the system : john.doe@xyz.com

When I am comparing these two,it should not fail because both the email ids are same. How can I make sure to compare this case sensitivity. I do not need a boolean result because, I am using map.get(emailID) .Please share your thoughts.

 
Best Answer chosen by Salesforce Beginner
Terence_ChiuTerence_Chiu
You can set both values to all lower case before comparing using String.toLowerCase so you won't have to worry about case. Below link has information on the method.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm#apex_System_String_toLowerCase

All Answers

Terence_ChiuTerence_Chiu
You can set both values to all lower case before comparing using String.toLowerCase so you won't have to worry about case. Below link has information on the method.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm#apex_System_String_toLowerCase
This was selected as the best answer
Salesforce BeginnerSalesforce Beginner
Yeah. Thanks Terence_Chiu_TCCloudDev. That worked. By default, salesforce stores the email ids in lower case. When I insert email ids to the map, I changed the case to lower.

That was very helpful :)