You need to sign in to do that
Don't have an account?
String comparison failing in Apex.
Hello ,
I a facing a strange issue while comparing two strings.
Scenario :
I have a custom link on account which is of type URl. the code for which is mentioned below
/apex/StringComparison?Id={!Account.Id}&start='account'
StringComparison.page code :
<apex:page standardController="Account" extensions="StringComparisonErrorV24">
</apex:page>
StringComparisonErrorV24 code :
public class StringComparisonErrorV24 {
public StringComparisonErrorV24(ApexPages.StandardController controller) {
System.debug('### StringComparisonErrorV24 constructor execution started...');
String rID = ApexPages.currentPage().getParameters().get('id');
String startedFrom = ApexPages.currentPage().getParameters().get('start');
System.debug('### rID --> '+rID);
System.debug('### startedFrom --> '+startedFrom);
if(startedFrom.equals('account')) {
System.debug('### they are same');
}
System.debug('### StringComparisonErrorV24 constructor execution finished...');
}
}
Issue :
When i am clicking on the custom link the line if(startedFrom.equals('account')) is returning false .
I was thinking of it should be returning true since I have hardcoded the same URL parameter. As a result i never
got '### they are same' line printed.
the debug log says the URL parameter is 'account'.
04:33:36.019 (19155000)|USER_DEBUG|[9]|DEBUG|### rID --> 00190000002g6xp
04:33:36.019 (19161000)|SYSTEM_METHOD_EXIT|[9]|System.debug(ANY)
04:33:36.019 (19174000)|SYSTEM_METHOD_ENTRY|[10]|System.debug(ANY)
04:33:36.019 (19184000)|USER_DEBUG|[10]|DEBUG|### startedFrom --> 'account'
Any thought would be of great help.
Thanks
Indranil
In your URL you have single quote marks around the word account, but in your apex code you don't have them. Does the URL actually contain the single quotes?
All Answers
In your URL you have single quote marks around the word account, but in your apex code you don't have them. Does the URL actually contain the single quotes?
Opps. I missed that. i should have removed the quotes from the URL itself.
Thanks for the quick response.
Regards
Indranil