listAccount=database.query('select id,name,BillingState,Phone,Website from Account where name Like '+searchString);

getting searchString value from vf page Having Following error:

expecting a colon, found 'sForce'

Error is in expression '{!displayAccounts}' in component in page interviewtwo: Class.InterviewTwo_Controller.displayAccounts: line 14, column 1

An unexpected error has occurred. Your development organization has been notified.

1 Answer 1


You need to include a string in quotes, or, even better, simply use a bind variable, which reduces the odds of SOQL injection:

listAccount = Database.query('select name, billingstate, phone, website '+
                             'from account where name like :searchString');

Generally speaking, though, a query like this can be inlined, since you don't have any dynamic query stuff going on:

listAccount = [select name, billingstate, phone, website
              from account where name like :searchString];

You must log in to answer this question.

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