+ Start a Discussion
Stuart Turnbull 9Stuart Turnbull 9 

SOQL - Searching for a % defined as a character in a string

Can anyone tell me how to search for a '%' inserted as text at the end of a Text string?

    LIKE '%[%]'  

This works fine in SQL. How would this work in SOQL?
Best Answer chosen by Stuart Turnbull 9
Alexander TsitsuraAlexander Tsitsura
Hi 

Use \%. 
Read this documentation: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_quotedstringescapes.htm

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.

Thanks,
Alex

All Answers

Alexander TsitsuraAlexander Tsitsura
Hi 

Use \%. 
Read this documentation: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_quotedstringescapes.htm

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.

Thanks,
Alex
This was selected as the best answer
Stuart Turnbull 9Stuart Turnbull 9
Sorry, that didn't work...

The criteria is...

FROM Task 
  WHERE Description LIKE '\%'

I also tried:

AND Description LIKE '%\%'

I'm looking for anything in the Task.Description where % is used as a text character at the end of the string.

I wen to the documentation, but don't see what I'm overlooking.

Thanks.

Stuart

 
Stuart Turnbull 9Stuart Turnbull 9
Disregard. The issue is not with the advice...it's that I'm trying to search on a Long Text Area, and that cannot be done with SOQL

Thank you for your assistance.

Stuart
Shyama B SShyama B S
Hi Stuart,
You cannot filter description in SOQL as it is a text area field. You can do the filtering in code like this:
For(Task t: [select id from task]){
   if(t.Description.contains('%')){
       //code
   }
}
If there are any more condtions, you can add that in the SOQL where condition.

Thanks,
Shyama