I am receiving an "Argument cannot be nulled error" when I add an attempt to set searchString to String.escapeSingleQuotes(preEscape)
in my class. The error appears upon loading the VF page. The VF page does not load when I add in the line that sets searchString to the above.
I believe the error is because String.escapeSingleQuotes cannot handle a null string, but where I would I set the value of the preEscape string? I attempted to set it at the beginning of the controller but it won't let me set the string unless I am in a method.
VF Page:
<apex:page controller="myClass" showHeader="true">
<apex:inputText id="searchString" value="{!preEscape}" onkeypress="return noenter(event);"/>
<apex:commandButton title="Search" value="Search" onclick="searchAccounts(); return false;"/>
</apex:page>
Controller:
public class myClass {
Public string preEscape{get;set;}
Public string searchString{get;set;}
public string searchType{get;set;}
public string searchWhere{get;set;}
public boolean searchLastName{get;set;}
public void searchAccounts() {
searchString = String.escapeSingleQuotes(preEscape);
if(searchType == 'lastNameSearch') {
searchWhere = 'Client_Last_Name__c = \''+ searchString +'\'';
searchLastName = true;
}
}
}