Find your content:

Search form

You are here

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

 
Share

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


Attribution to: Shane McLaughlin

Possible Suggestion/Solution #1

Another alternative to add cookies

Use Cookie Manager for chrome

Add like below screenshot

enter image description here


Attribution to: Ratan Paul

Possible Suggestion/Solution #2

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.


Attribution to: Shane McLaughlin

Possible Suggestion/Solution #3

document.cookie = "debug_logs=debug_logs; path=/; domain=.force.com; value=debug_logs" ;

Add that to your page to set this cookie for the session.


Attribution to: Ben Patterson

Possible Suggestion/Solution #4

Update

This is no longer needed as of Spring '18

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?edition=&impact=

Original

For API requests, i.e. webhooks, your only real option is a proxy to set this cookie.

I've got a node proxy working in our sandbox. I've made the repo public

var httpProxy = require('http-proxy');
var express = require('express');
var apiProxy = httpProxy.createProxyServer({target: process.env.TARGET, changeOrigin:true});
apiProxy.on('proxyReq', function(proxyReq, req, res, options) {
  proxyReq.setHeader('Cookie', 'debug_logs=debug_logs,domain=.force.com');
});
var addDebugCookie = function(req, res) {
  apiProxy.web(req, res);
};
var server = express();
server.all('/*', addDebugCookie);
var port = process.env.PORT || 5000;
server.listen(process.env.PORT || 5000)

Planning on setting this up on Heroku and then running all our webhook callbacks through this so we can turn on debug logs when something misbehaves.

UPDATE - we've started using this in production and everything is working fine so far, high level setup was:

  • create a heroku app (or any other node.js hosting provider)
  • deploy code to it
  • set TARGET environmental variable to your force.com site
  • update any callouts to use proxy url instead of force.com sites url

Attribution to: Ralph Callaway

Possible Suggestion/Solution #5

Adding to Shane's answer-

The release notes which were linked to above include specific instructions for setting the cookie in Chrome, but not in Firefox. Here's one way of doing it in Firefox:

  1. Install the Cookies Manager+ add-on
  2. Create a cookie that looks like this: enter image description here

Attribution to: Martha Seneta

Possible Suggestion/Solution #6

Chrome & Edge

The above answers are not so clear instructions for winter 17 release .For winter 17 release open the public site first by clicking on the links in the Develop | Sites | Site

And once you are in the site, use Chrome developer console or Edge developer console and key in below

document.cookie ="debug_logs=debug_logs;domain=.force.com";

The help article does a good job of explaining this.


Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1149

My Block Status

My Block Content