How to get Debug logs for site guest user
By: Yathansh Sharma On: November 23, 2017
To any Salesforce developer the debug logs are one of the most important thing while working on the apex classes. At any point if we want to check the current data on a variable, of check the flow of execution of the current function we use System.debug() function for that. However, this functionality is not available for the site guest user. The logs created for any site guest user are not recorded by salesforce. Hence debugging becomes quite complicated in that scenario. Here I am going to give you a solution for this problem, and tell you how to create debug logs for site guest user.
Creating an entry for User
The first thing that we need to do here is create a User Trace Flag entry for the guest user for the site we are going to debugging.
Go to Setup|Logs|Debug Logs and in the user trace flags click on New.
Here Traced Entity Type should be user, in Traced Entity Name select the site guest user for the site that you want to test. Set the start date of today and end date of tomorrow same time, and the Debug Level to standard SFDC_DevConsole. Click on save after setting all the values.
With this done, open the site in a new tab. All the generated logs will be shown in the Debug Logs page for each VF page that we open here. However you can see that when you refresh the Debug Logs page nothing will come up. This is because you need to set a cookie in the browser console before SFDC can start generating logs.
Open the browser console window and write this line:
and then press enter.
Once you add this field, refresh the page and see the debug logs page. A new log entry will be created according to our need.
As you can see that in this example the log is now visible for the page that we opened on the site. You can view these logs and get all the information that you get in any normal log.
That’s all about generating logs for the site guest user in Salesforce, for any further queries feel free to contact us at:
Or let us know your views about this blog in comments section below.