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


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)+'\'%';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.