1

I am creating a dynamic query.

string s = '%' + searchText + '%';
string query = 'Select name, ShippingCity, ShippingState, ShippingCountry, rating, type, Industry, ownerId From Account Where name LIKE : '+s+' OR BillingAddress LIKE : '+s+' OR website LIKE : '+s+' OR AccountNumber LIKE : '+s;

System.QueryException: line 1:122 no viable alternative at character '%'

1 Answer 1

2

You need to wrap it in single quotes, not precede it with a colon (:).

String s = '\'%' + String.escapeSingleQuotes(searchText)  + '%\'';
... 'LIKE ' + s + '...';

Or if you want to use bind variables, you can just wrap your searchText variable:

searchText = '%' + searchText + '%';
... 'LIKE :searchText ...';
0

You must log in to answer this question.

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