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

Set cookie on site to get debug logs

I have a site that sometimes has an unhandled execption, it happens.  Normally I'd just turn on logging for that guest user and see what the people were doing wrong.  After winter '17, users will have to have a special cookie for logs to be created.

My thought was to set this special cookie whenever the user accesses the site.  That way I can just turn on logging when needed.

I see the setCookies method, but that adds the apex__ prefix to the name.  Is there another way?  I'm just an admin code hacker, so forgive me.
Jayamaruthyraman JaganathJayamaruthyraman Jaganath
Hi BenP,

I found the following and thought it might be helpful!
Right, that's how to set a cookie manually.  I'd like to have this happen when they load the page, or click a button on the page.

To Set it Manually

First you need to navigate to the Site Url In ur Browser and then Click on Developer tools and then Execute below script through Developer console.

document.cookie ="debug_logs=debug_logs;";

To Set it through Code

Create an instance of Cookie Class

and then use setCookie Method

The setCookies method adds the prefix “apex__” to the cookie names.  Wouldn't that cause an issue?
Not Sure, but we can try, as it seems like the only option available for now within Apex
I managed to get my class to set a cookie, but it doesn't cause a log entry.  The reason is that the name and domain do not match what salesforce wants.  They want the name to be debug_logs and the domain to be  The set cookie method prefixes "apex__" to the name and I don't see where you can set the domain at all.

I welcome feedback.
I found that adding this line of code in the java section of my vf page works. document.cookie = "debug_logs=debug_logs; path=/;; value=debug_logs" ;