You need to sign in to do that
Don't have an account?
David Holland 6
Strange behaviour with boolean value of dynamic query string
Hi all, hoping someone can help.
I won't bore you with the ins and out of the code, but basically, I have a query string I am dynamically populating from an SObject and seeing if it is true.
The code snippet is below:
It is returning me these two debugs and I have no idea why!
qforcesupport@quintessentially.com == qforcesupport@quintessentially.com
false
So it is stating that the two values are not the same....
Please someone help!
I won't bore you with the ins and out of the code, but basically, I have a query string I am dynamically populating from an SObject and seeing if it is true.
The code snippet is below:
private static Boolean shouldShowInInbox(String queryString, SObject sObjectToCheck, Set<String> fieldsToCheck){ for(String fieldToCheck : fieldsToCheck){ String fieldValueOnObject = String.valueOf(sObjectToCheck.get(fieldToCheck)); queryString = queryString.replaceAll(fieldToCheck, String.isBlank(String.valueOf(fieldValueOnObject)) ? '' : String.valueOf(fieldValueOnObject)); } System.debug(queryString); System.debug(Boolean.valueOf(queryString)); return Boolean.valueOf(Boolean.valueOf(queryString)); }
It is returning me these two debugs and I have no idea why!
qforcesupport@quintessentially.com == qforcesupport@quintessentially.com
false
So it is stating that the two values are not the same....
Please someone help!
This is bcz of Boolean class valueOf method behaviour. In your code Boolean.valueOf(queryString), in this statement valueOf method just look for string value 'true' and if it is other than 'true' then it will return false. In your code value of queryString is qforcesupport@quintessentially.com == qforcesupport@quintessentially.com and not string of 'true'.
Plz refer this link for more information. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_boolean.htm
All Answers
This is bcz of Boolean class valueOf method behaviour. In your code Boolean.valueOf(queryString), in this statement valueOf method just look for string value 'true' and if it is other than 'true' then it will return false. In your code value of queryString is qforcesupport@quintessentially.com == qforcesupport@quintessentially.com and not string of 'true'.
Plz refer this link for more information. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_boolean.htm
Of course,how stupid of me.
Is there a way to dynamically fire that queryString to return me the boolean of it?
I am struggling to find any documentation to allow me to do so.
I am not sure about any method but you can use split method to split this string and then compare two strings. For example.
Plz let me know if this works for you.
Plz replace if stmt with below stmt. I miss out trim() method.
This will remove spaces in string and then match.
Please let us know if this will help you
Hope above post help you to resolve your issue. Kindly mark this as best asnwer, this will help others if they face same issue.