1

I'm trying to use String.escapeEcmaScript(data) in an Apex REST class, but it seems like String class is not visible.

@RestResource(urlMapping = '/Test/*')
global class TestREST {

  @HttpPost
  global static void createTest(String message)
  {
    RestContext.response.addHeader('Content-Type', 'application/json');
    RestContext.response.responseBody = Blob.valueOf('{ "message" : "' + String.escapeEcmaScript(message) + '" }');
  }

}

Am I missing something, or is it just not possible to use this class since it's not global?

1 Answer 1

3

The code should be:

message.escapeECMAScript();

escapeECMAScript is not a static method of the string class, it must be called from an existing string object

1
  • 3
    Also, it would be advised to check to make sure message is not null prior to calling escapeECMAScript() on it so that you don't throw a NPE.
    – Mark Pond
    Jun 26, 2015 at 17:51

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.