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) { searchWhere = String.escapeSingleQuotes(preEscape); }