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
geniotgeniot 

escaping apostraphe and backslash revisited

Hello,
I've done some search in the forum and managed to run queries without 'malformed' exceptions.
Although I cannot get the account's name in salesforce right:
Pdq \'&"\\he Rockies
For test's sake my primary string was:
Pdq '&"\he Rockies
I'm escaping it with:
               elementValue = elementValue.replaceAll("\\\\","\\\\\\\\");
               elementValue = elementValue.replaceAll("\\'","\\\\'");
Note: backslash should be escaped before apostraphe =), otherwise it won't work.
After escaping the java string in the debugger looks like:
Pdq \\'&"\\\\he Rockies
and that's what is sent in the query.
Hopefully you'll see that post like I wrote it. Otherwise  check out the screenshot:

Regards,
Vitaly

 


geniotgeniot
Could you at least tell whether it is a TODO issue, because I need to report to my client on the status of this problem.
Thanks,
Vitaly
SuperfellSuperfell
Your escaping code seems wrong, you're only escaping \' (\\') not just ' (\'), Ron posted a regex recently to handle the SOSL escaping rules, check that out.
geniotgeniot
Alright, I found the problem. I was escaping apostrophes and backslashes for all input data. But in fact only strings within queries should have been escaped.
As a result of my mistake the fields of salesforce objects where propagated with escaped strings as well and hereafter populated to salesforce.
Thank you for your help.
KerrySainsburyKerrySainsbury
It's a shame you don't seem to be able to search blogs to find the post you mention...

:-(