You need to sign in to do that
Don't have an account?
String Compare
Hello SFDC Gurus,
I am not able to explain my code below. Why is it giving such results? Would appreciate if anybody can help me with this behaviour.
Thanks in advance,
K
if(objectNameLabelMap.size() == 0){
for(Schema.Sobjecttype obj : objectMap.values()){
objectNameLabelMap.put(obj.getDescribe().getName(),obj.getDescribe().getLabel());
}
}
set<string> setObjName = objectNameLabelMap.keySet();
//get the api names of object labels. lstStr = {Contact, Account}
for(String str2 : lstStr){
for(string str : setObjName){
System.debug('str2:' + str2 + '\t str: '+ str + '\t objectNameLabelMap.get(str):'+ objectNameLabelMap.get(str));
System.debug('objectNameLabelMap.get(str).equalsIgnoreCase(str2):'+ objectNameLabelMap.get(str).equalsIgnoreCase(str2));
System.debug('objectNameLabelMap.get(str).compareTo(str2):'+ objectNameLabelMap.get(str).compareTo(str2));
String tmpObjName = objectNameLabelMap.get(str).trim();
System.debug('str2.length():'+ str2.trim().length());
System.debug('tmpObjName.length():'+ tmpObjName.length());
System.debug('tmpObjName.compareTo(str2):'+ tmpObjName.equalsIgnoreCase(str2));
if(tmpObjName.equalsIgnoreCase(str2)){
System.debug('Found match!!');
lstOfSearchObjectNames.add(str);
break;
}
-------------------------------------------------
Debug output:
-------------------
str2: Account str: Account objectNameLabelMap.get(str):Account
objectNameLabelMap.get(str).equalsIgnoreCase(str2):false --- WHY??
objectNameLabelMap.get(str).compareTo(str2):33 ---- HOW??
str2.length():7
tmpObjName.length():7
tmpObjName.equalsIgnoreCase(str2):false