0

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;
}
}
}
1
  • 1
    That controller shouldn't compile. Please include your code and any error messages exactly as they are in your org. You're also calling Javascript functions which you haven't defined on the page.
    – Adrian Larson
    Commented Feb 6, 2018 at 21:58

1 Answer 1

2

You don't need to escape the characters if you simply use a binding statement:

searchWhere = 'Client_Last_Name__c = :preEscape';

For sake of argument, if you did need to escape it, check for a null value first:

if(preEscape != null) {
    searchString = String.escapeSingleQuotes(preEscape);
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .