How can I get a debug log for the sites guest user/public profile? [updated for Spring 18]

  • Normally, you can put debug monitoring on a user by name to see the details on the error they're getting (especially for the non-descript Error Loading a Visualforce Page).

    But when you are trying to debug a site page, how do you get a debug log for the guest user?

    Update

    As of Spring '18 Salesforce has dropped the requirement to include the debug_logs cookie to get debug logs for the force.com site requests.

    In Winter ’17, we introduced a change that required guest users to set browser cookies to activate debug logging. We had the best of intentions: All your public site visitors share one guest user license. Thus, when you enable logging for the guest user, the visitors’ collective activities can fill your debug logs quickly, hitting the log-size limit and causing log truncation. Sadly, people didn’t like the Winter ’17 change. Setting cookies is complicated, and the change made collecting debug logs for public users’ asynchronous activity impossible. We’ve seen the error of our ways. Your public users no longer need a debug_logs browser cookie to trigger logging. This change applies to both Lightning Experience and Salesforce Classic.

    https://releasenotes.docs.salesforce.com/en-us/spring18/release-notes/rn_forcecom_debugging_guest_user.htm

  • Go to Monitoring>Debug log.

    Where you would normally put the username, put the name of the Site.

    For example: If your site is called MySite, enter MySite as the user name. Shockingly undocumented, but this gives you the debug you're looking for.

    ATTENTION:

    Winter17 is making a change to this--you'll now need to ALSO set a specific cookie in the guest user's browser to enable this.

    https://releasenotes.docs.salesforce.com/en-us/winter17/release-notes/rn_forcecom_debugging_guest_user.htm#rn_forcecom_debugging_guest_user

    Related Idea Exchange Idea for Integrations

    The requirement for such a cookie is incompatible when building web-hook services for 3rd parties, there is an Idea Exchange post here to provide an IP whitelist as an alternative.


    Update from Spring '18 release notes:

    In Winter ’17, we introduced a change that required guest users to set browser cookies to activate debug logging. We had the best of intentions: All your public site visitors share one guest user license. Thus, when you enable logging for the guest user, the visitors’ collective activities can fill your debug logs quickly, hitting the log-size limit and causing log truncation. Sadly, people didn’t like the Winter ’17 change. Setting cookies is complicated, and the change made collecting debug logs for public users’ asynchronous activity impossible. We’ve seen the error of our ways. Your public users no longer need a debug_logs browser cookie to trigger logging. This change applies to both Lightning Experience and Salesforce Classic.

    Thats true, I was surprised about the same :)

    Worth noting here that it's the Site Name field (which you mention name in the answer) and not the Site Label, so if your Site Label is "My Great Site" the value to put in the debug log would be the Site Name "My_Great_Site".

    Peter, I didn't know that...all my sites don't have spaces!

    One other method to determine the name of the Username of the anonymous/guest user is through this path: Setup > Develop > Sites > [click on site label] > Public Access Settings (button) > Assigned Users (button)

    @Shane, you're awesome! Thank you for figuring this out, and for posting this Q&A!

    +1 For mentioning the Winter17 change Salesforce own docs did not mention it

    Sadly, I have tried this in 5 different orgs and have yet to be able to get a debug log using the methods described. Also, had not idea it was so difficult to create a cookie manually.....Can anyone confirm it is indeed working?

    I tried it and its working well .

    @MohithShrivastava - I think the issue is i am logged into the org as a package provider that user has granted support access to so the log is requested by an alias but the dev console it running under the user. or something weird like that. or i am just setting the cookie wrong. Either way our ability to debug guest users seems to have dissapeared....guess i will try it in our lma org as see if it works there

    @MohithShrivastava - I just tried this again with my own sandbox org and still no logs. Seems in every sandbox I am in the Debug Log panel in the UI is empty. No logs ever appear even for full users, although for full users the logs appear in dev console. So frustrating.....I did get it working in chrome though....

    what if its coming from an API?

    Finally great news. No need to set the cookies now

    I've tried this and logs still don't happen. SETUP > Logs > Debug Logs. New. Traced Entity Type: User Traced Entity Name: [sitename] Site Guest User Start Date: now Expriation Date: this time tomorrow Debug Level:SFDX_DevConsole I send data through the REST endpoint and nothing happens -- no logs.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM