Is there any method similar to "escapeSql" that is available on SalesForce platform. This would be a great feature and will be very useful method for companies whose data is global where Names might contain special characters.


1 Answer 1


For URL encoding, there is EncodingUtil.urlEncode('StringToEncode', 'UTF-8);

The apex String class offers a number of built in escape*() methods. You would typically need to choose the one that matches what you are doing.

For building dynamic SOQL queries you would typically use escapeSingleQuotes. See SOQL Injection.

There is also escapeUnicode().

What are you intending to do with the escaped values?

You may need to combine several of the built in methods to meet your requirements.

  • Hi Daniel, I have a scenario where I have to escape single apostrophe, double apostrophe's as well as german language letters. I have to pass account name in a URL for Contact VF Page. Updates on the contacts are failing because of Account Name having special characters. Tried using escapeUniCode() method that is only taking care of german characters but not the apostrophe's. Just for apostrophe's I have to use another function. So I was wondering if there is any single method that can be implemented for all the special characters across.
    – DJD
    May 29, 2015 at 1:01
  • @Giene Does the EncodingUtil.urlEncode method successfully handle the german language characters? If not, could you add some sample strings to your question? May 29, 2015 at 2:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .