Skip to main content

Posts

Showing posts from November, 2021

Map contains key is case sensitive

 Here is my previous post related to map contains method.  How contains key method works ? Does it allow partial matches or exact matches ? We know map contains key method is case sensitive. if you are create a key using First Name , Last Name and DOB to find unique Account record then system will consider 2 different record for below scenario. 1. First Name - "Capital"  Last Name- "Testing" DOB- 01/01/1989 2. First Name - "CAPITAL" Last Name - "TESTING" DOB- 01/01/1989 The work wound is  map<String,Account> map_Name_Acc = new map<String,Account>(); String sKey = ''; for(Account acc:[SELECT firstname,Lastname,DOB__c from Account limit 10]{      sKey = acc.FirstName+'_'+ acc.LastName+'_'+acc.DOB__c; // this will create duplicate records since key is case sensitive  sKey = acc.FirstName.toLowercase()+'_'+ acc.LastName.toLowercase()+'_'+acc.DOB__c;  } toLowercase() - convert name to lower case, ...

How to split String from the character '*' ?

 This is a bug in split function, it does not work for '*'  or '+'.  We will get runtime error. System.StringException: Invalid regex: Dangling meta character '*' near index 0 *  String sBody = '*   Building Name:Brookwood Gardens  *   Is your unit isolated with barrier systems in place?Yes  *   Does your unit have its own supplies?Yes  *   Does your unit have any additional infection control equipment?HVAC filters: YesUVC lights: Yes'; List<String> strList = sBody.split('*'); // This will throw error. system.debug('strList '+strList); Solutions:  List<String> strList =sBody.split('\\*');  // This will solve.