+ Start a Discussion
Jay16Jay16 

Invalid character '*' found in the filter value "%*%" used with the "like" operator.

Hey Guys, 

My query is returning this error when I search using * . Other characters are fine. 

System.UnexpectedException: Invalid character '*' found in the filter value "%*%" used with the "like" operator.

Here's the part of the query that's causing the error:

qString+= ' and (Product2.Name like \'%' + searchString + '%\' or Product2.Description like \'%' + searchString + '%\' or Product2.Family like \'%' + searchString + '%\' )';

Does anyone know how I can update it to allow asterics *  ??

Thanks

Best Answer chosen by Jay16
PratikPratik (Salesforce Developers) 
Hi Jay,

In SOQL , LIKE operator support Only % and _ wildcards. As "*" is not supported in Like , you are facing the error.
 
  • The % wildcard matches zero or more characters.
  • The _ wildcard matches exactly one character.

For more details on comparison operators supported:
https://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_select_comparisonoperators.htm

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
 

All Answers

PratikPratik (Salesforce Developers) 
Hi Jay,

In SOQL , LIKE operator support Only % and _ wildcards. As "*" is not supported in Like , you are facing the error.
 
  • The % wildcard matches zero or more characters.
  • The _ wildcard matches exactly one character.

For more details on comparison operators supported:
https://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_select_comparisonoperators.htm

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
 
This was selected as the best answer
Jay16Jay16

Thanks Pratik, 

I ended up having to replace the * for a 0 which isn't ideal. 

I was confused because the standard product search accepts * as long as it has other characters. Aparently this is because it is Oracle based and has different rules. 

PratikPratik (Salesforce Developers) 
Hi Jay,

Yes "*" is considered as wildcard character in search but LIKE operator doesn't support it. 

Thanks,
Pratik