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
Vishal Tiwari 36Vishal Tiwari 36 

Apex Strings : Pipe symbol (|) is converted to | in string variable while querying

Hi All, 

I'm trying to query a field on Object__c which stores information like (1001|01).

Example:
 
String str = '\'1001|01\'';
List<Object__c> recordList = [SELECT ID FROM Object__c WHERE Field__c includes (str) LIMIT 50000];

Exception Message is shown as below:
 
"common.apex.runtime.impl.ExecutionException: expecting a right parentheses, found '&#124;'"


Below are the list of things I have already tried to stop pipe symbol from getting converted into it's Unicode:

1. unescapeHtml4()
System.debug(str.unescapeHtml4());

2. EncodingUtils.urlDecode();
String str = '\'1001%7C01\''; // %7C is equivalent to pipe (|) symbol
System.debug(EncodingUtil.urlDecode(str, 'UTF-8'));


3. replace() and replaceAll() methods to convert &#124; to pipe symbol dynamically
All the above ways failed to get the required results.

Any other help or direction would be appreciated.

Thank you
Suraj Tripathi 47Suraj Tripathi 47
Hi Vishal,
Try this one,it may help you
String str = '1001'+'|'+'01';
List<Object__c> recordList = [SELECT ID FROM Object__c WHERE Field__c includes (str) LIMIT 50000];

If you find your Solution then mark this as the best answer.

Thank you!
Regards,
Suraj Tripathi  
 
SwethaSwetha (Salesforce Developers) 
HI Vishal,
I tried a similar code in Anonymous block and it works
String str = '\'1001|01\'';
List<Account> recordList = [SELECT ID FROM Account WHERE AccountSource = :str];

String str = '\'1001|01\'';
String query = 'SELECT ID FROM Account WHERE AccountSource includes(' + str +'))';
I also see you also reached out on https://salesforce.stackexchange.com/questions/357132/apex-strings-pipe-symbol-is-converted-to-124-in-string-variable-while-q which has been addressed by sfdcfox according to which the issue could be else where in the code

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you