Im testing an apex class that I got from
Jeff Douglas' page

but the I'm getting a "Error Error: Compile Error: line 61:76 no viable alternative at character '%' at line 61 column 76"

soql = 'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null';
if (!firstName.equals(''))
  soql += ' and firstname LIKE ''+String.escapeSingleQuotes(firstName)+'%'';
if (!lastName.equals(''))
  soql += ' and lastname LIKE ''+String.escapeSingleQuotes(lastName)+'%'';
if (!accountName.equals(''))
  soql += ' and account.name LIKE ''+String.escapeSingleQuotes(accountName)+'%'';  
if (!technology.equals(''))
  soql += ' and interested_technologies__c includes (''+technology+'')';

I already created a Interested Technologies picklist. What am I doing wrong? Please advise thanks

1 Answer 1


you can't use single quote in text, because it is escape character. You can change them to following format:

 soql += ' and firstname LIKE \''+String.escapeSingleQuotes(firstName)+'\'%';

You must log in to answer this question.

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