function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Medhanie HabteMedhanie Habte 

Unexpected token error with apostrophes in lookup/create page

Greetings, I've developed a lookup page for a Salesforce app we're building. The lookup page, which locates contacts and accounts is based on Jeff Doglas's roll your Salesforce "LookUp" Popup window ( However, every time I input or search for a record with an apostrophe " ' " in it. I return a unexpected error. Are they any suggestions you can provide for enabling the inclusion of apostrophes in the code. Hope it helps.
Best Answer chosen by Medhanie Habte
Alexander TsitsuraAlexander Tsitsura
Hi Medhanie,

Maybe u using dynamic query, see example below
soql =  'select name from account where name LIKE \'%' + searchString +'%\'';
if searchString contains info with ', you query look as
select name from account where name LIKE %Account's%

And error in ' in LIKE statement.
You can create variable and use it in query.
String queryName = '%' + name + '%'; // name = "Name's"
queryResult = [SELECT Id, Name FROM Account WHERE Name like :queryName];


soql = 'select name from account where name LIKE :queryName';

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.