0

UPDATE:

SELECT Id, Name, Signature FROM User WHERE Signature = 'This is a test, 
this is a another test, 
this is a last test'

the above query returns the data only after I have split that in lines

Any explanation? I do not see any HTML code in the field

END UPDATE

I'm trying to write simple SOQL query that has comma in it.

SELECT Id, Name, Signature FROM User WHERE Signature = 'This is a test, this is a another test, this is a last test'

If i run the above SOQL I do not get any result and I even tried with LIKE

SELECT Id, Name, Signature FROM User WHERE Signature LIKE 'This is a test, this is a another test, this is a last test%'

Is there a way escape the comma?

  • Did you try simply replacing the comma with a %? – Eric Aug 31 '17 at 15:17
  • You could also use _ as a wildcard that matches a single character. – Adrian Larson Aug 31 '17 at 15:21
  • 1
    Are you trying to query records where the Signature is literally This is a test, this is a another test, this is a last test, or are your commas separating 3 separate possible signatures that you're trying to search for (e.g. Signature = 'This is a test' OR Signature = 'this is another test' OR Signature = 'this a last test')? – Derek F Aug 31 '17 at 15:22
  • So, there are literal blank lines in your signature? You'd use \n to escape those. The commas are just fine. – sfdcfox Aug 31 '17 at 16:16
  • did not work if I use the \n to escape – Nick Kahn Aug 31 '17 at 16:30
1

The only characters you need to escape are listed in Quoted String Escape Sequences, which are \r, \n, \t, \b, \f, \', \", \\, \_, and \%. Commas do not need to be escaped. The most typical cause for a query not to return values is duplicated spaces (e.g. This is a test instead of This is a test). Try querying the record and checking out what's actually in the field. Also, there might be HTML in the field, which you would also need to account for.

  • I have updated my question, any explanation to it? – Nick Kahn Aug 31 '17 at 16:15
  • @NickKahn Perhaps you're on Windows? In which case, the field might literally contain \r\n. What if you said SELECT Name, Signature FROM User WHERE Signature LIKE 'This is a test,%'? I would expect that to work. The point is, you'd have to work what's in the whitespace if you wanted to include it in the filter. – sfdcfox Aug 31 '17 at 17:24
0

Here is how I able to make it work, hope this will help others:

string s = 'This is a test,'+'\r\n'+'this is a another test,'+'\r\n'+
'this is a last test';

SELECT Id, Name, Signature FROM User WHERE Signature =: s;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.