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
amarnijeramarnijer 

Soql query error during special character search

Hi I have 2 SOQL queries, both are used for search.

 

First query is working fine, i.e.

 

select FirstName,LastName,Title,Street,Company,LeadSource,Email,Owner.Name,Rating FROM Lead where Createddate < LAST_WEEK AND
Status = 'Open' AND (Rating ='Hot (Probably Order)' OR RecordTypeId IN
('012800000007S5iAAE','012800000007IumAAE','01280000000LmL3AAK','012800000007TxvAAE')) and (FirstName like 'Kevin(%'or LastName
like 'Kevin(%'or Company like 'Kevin(%'or LeadSource like 'Kevin(%'or Email like 'Kevin(%'or Owner.Name like 'Kevin(%'or Rating
like 'Kevin(%'or Street like 'Kevin(%'or Title like 'Kevin(%') order by FirstName asc NULLS FIRST

 

Second one is giving error like "Invalid character found in the filter value "Kevin(%" used with the "like" operator."

the second query is below

 

select FirstName,LastName,Title,Street,Company,LeadSource,Email,Owner.Name,Rating FROM Lead where Createddate < LAST_WEEK AND
Status = 'Open' and (FirstName like 'Kevin(%'or LastName like 'Kevin(%'or Company like 'Kevin(%'or LeadSource like 'Kevin(%'or
Email like 'Kevin(%'or Owner.Name like 'Kevin(%'or Rating like 'Kevin(%'or Street like 'Kevin(%'or Title like 'Kevin(%') order
by FirstName asc NULLS FIRST

 

Can any one help me to find out the error?

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
amarnijeramarnijer

I got the answer. I update the api version of the class from 20 to 27. and it is working fine. Thank you.

All Answers

Bhawani SharmaBhawani Sharma
Useing Kevin% only . remove ( sign
amarnijeramarnijer

Hi Tech Force, Thank you for your reply. I have data like "Kevin( asc@#$%^&*)". I know this a test data, but original record might have some data with special characters. so I want to write some logic where user can give search string with special character like "Kevin( asc@#" and get the matching data.

Bhawani SharmaBhawani Sharma
If this is the case then hold your value in a variable first and then use that variable
Like
String nameVal = 'Kevin( asc@#$%^&*)' + %;

where Name Like: nameVal
amarnijeramarnijer

I got the answer. I update the api version of the class from 20 to 27. and it is working fine. Thank you.

This was selected as the best answer