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, "CAPITAL" and "Capital" will be "capital"
No comments:
Post a Comment