A few years ago, Salesforce disabled debug logs for REST guest calls. The only way to enable generating the logs is to add a cookie to the incoming call. Docs here.

The incoming call in my case is coming from Twilio. Twilio says you can add a cookie by returning a set-cookie parameter in the response header.

However, the docs on RestResponse say:

Please note that the following headers aren't allowed: cookie set-cookie

And, indeed, when I try this:

        RestContext.response.addHeader('Set-Cookie', 'debug_logs=debug_logs');

... Twilio tells me the response was an Apex exception:

"errorCode": "APEX_ERROR",
  "message": "System.InvalidHeaderException: Header name \"Set-Cookie\" is not allowed.\n\nClass.System.RestResponse.addHeader: line 13, column 1\nClass.proton7.IncomingSMS_MMS.handleSMS_MMS: line 100, column 1"

So, at least the docs are correct. But that leaves me with no way to set a cookie, and no way to generate some much-needed debug logs.

Any workarounds you can think of?

(I have a support ticket in to Twilio, asking if I can set the cookie via their console, or with a cUrl.)

  • What Twilio product/service is making the call to SF API? – identigral Jun 21 '19 at 6:21
  • It's the Messaging API – PatMcClellan__c Jun 21 '19 at 16:50

Found an undocumented solution that's much easier than setting a cookie. Despite documentation that says Salesforce disabled logs for REST Guest User, turns out, you can set up a trace log on it.

I had been trying to set up the trace log on the Apex Class that handles the incoming call to the REST site, but the Guest User activity didn't generate logs. Instead, just search for the name of the site in the User lookup. It will find the Site's Guest User profile, and voila! Logs.

enter image description here

| improve this answer | |

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.