You need to sign in to do that
Don't have an account?

Possible to escape special characters in SOQL??
I'm having problems with a SOQL statement in one of my ajax pages and from what I can tell in the docs, it's not possible to do a "like" search and escape special characters... True?
Basically, I have a soql statement that takes in a value entered by the user. If the value contains a single quote, the soql breaks. I've tried escaping with ( \ ) I've tried replacing the singel quote with two single quotes ala SQL and I've tried replacing the single quote with ' and none of it works.
Is there a solution to this or should I just cut off the stuff after the quote and search on that?
Thanks,
-Zach
Basically, I have a soql statement that takes in a value entered by the user. If the value contains a single quote, the soql breaks. I've tried escaping with ( \ ) I've tried replacing the singel quote with two single quotes ala SQL and I've tried replacing the single quote with ' and none of it works.
Is there a solution to this or should I just cut off the stuff after the quote and search on that?
Thanks,
-Zach
var city = document.getElementById("city").value;
if (document.getElementById("city").value.indexOf("'") != -1) {
//alert("there's a '");
city = city.replace(/'/g,"\\'");
}
who = who.replace(/([\'\&\|\!\(\)\{\}\[\]\^~\:\\\+\-])/g, "\\$1");
Message Edited by Ron Hess on 05-23-2006 11:03 PM
<script type="text/javascript" src="/js/functions.js"> </script>
<script>
var who = "{!Lead.Product_Description__c}".replace(/([\"\'\&\|\!\(\)\{\}\[\]\^~\:\\\+\-])/g, "\\$1");
alert(who);
</script>
</head>
</html>
var who = "2" Square/Diamond Paper Sticker - Other sizing??".replace(/([\"\'\&\|\!\(\)\{\}\[\]\^~\:\\\+\-])/g, "\\$1");
1) Not completely Salesforce's fault that it breaks things, per se; JavaScript doesn't have a multi-line quote feature like Perl does. If you install a Perl scripting language in your browser and use that in a tag, you'll find that multi-line quotes are simple and efficient to get things working.
2) You can, however, use SUBSTITUTE() in a formula for fields with known problems to replace carriage returns and double-quotes with escaped versions and query the result of the formula instead.
3) Don't query if you can retrieve; retrieve gets you the information you want, but is faster than a query (strictly uses the index, and is presumably optimized for this very type of purpose).
BTW, a query call with a just a where id='foo' clause performs the same as a retrieve call (they both build the internal query representation and execute it).
I am not able to use the following code to escape quotation charater ".
var="{!Case.Reference_Type__c}".replace(/([\'\"\!\@\#\$\%\^\&\~\*\(\)])/g, "$1");
plz help!!