So you want to learn: How to use new Debug Logs (Winter'16)
Atul Gupta
Building Global Products and Services Companies from India........ Hire Talent | Salesforce Apps and Services | IT Services
Hardly new now I suppose. It's been quite some time since the release of Winter'16 but due to the lack of some good articles on this subject, here it is for your (All the Awesome Salesforce Developers out there) eyes only.
After the Salesforce orgs got migrated to Winter'16, I was sweetly surprised with the change I saw in the Debug Log View specially in the upper section where I used to add users. Frankly I freaked out.
I was used to seeing this screen, but folks, it's gone, now we will never be able to see this screen again and for good.
I am sure you were suffering from the same frustration and irritation for so many years, where you had to add the user again and again, just after executing the code for a couple of times. Alright, I had 20 logs but c'mon that used to get finished even before I start testing my code.
Salesforce has finally listened to our plight and removed the 20 logs per user at a time limit.
Now the limit is still there but it's a time limit rather than the number of logs. Let me take you through the rather confusing(only at first) interface of the new debug logs.
The lower section is not at all changed actually, but in the upper section instead of "Monitored Users" we have "Use Trace Flags" section, yes now instead of setting up users we will be setting up trace flags. You will find one trace flag already added for you by default.
A Trace Flag includes,
- debug level
- a start time
- an end time
- a log type
Log Types can be of 3 types:
- DEVELOPER_LOG, logs your activities (logged in User)
- USER_DEBUG, logs an individual user's activities (any user you specify)
- CLASS_TRACING, doesn't generate logs, but overrides logging levels for the Apex Classes and Triggers you specify
Don't get confused, we will be covering this in detail later. First let us understand how to set a trace flag for all these types. Now I've already specified what a trace flag consists of, you need to provide all this information in order to create a trace flag.
When you will click on the "New" on the debug log setup page, you will arrive at the following screen
The different components are,
Traced Entity, for whom or what you want to generate logs, you can choose one of the following
- User
- Apex Class
- Apex Trigger
Now, for User you will see a trace flag added when you click on Save but for Class and Trigger you won't see any trace flags. But you can see these trace flags via Developer Console (I know this is confusing, but that's the way it is), We'll come to Developer Console in a while.
Put a Start Date and Expiration Date, now the catch here is you can't have the difference between these two dates more than 24 hours. This got me really confused at first, but the best way to go about this is to choose the Start Date and Expiration Date by clicking on the current date time shown to the field's right side and then increasing the date of Expiration Date by 1, i.e.
Start Date = 3/2/2016 12:46 PM
Expiration Date = 3/3/2016 12:46 PM
Obviously, you can choose any number of hours of difference between the two dates, the default is 30 mins.
Debug Level, here you specify the filters that are used in the logs. Clicking on the magnifying glass will show you this pop up window
Now this window won't show any search term or records when it will open, but to search for the default Debug Level, SFDC_DevConsole you will have to search with "*", just click on the "Go" button won't help, I know this is another confusing thing, but we got this working right.
If you want a different set of Logging Levels, you can click on "New" button and you will see this screen in the same popup
Specify the name and choose the Log Levels for each Log Category. Save and you have created a new Debug Level, which you can use for any number of trace flags you create. You can set up different Debug Levels with different Log levels to keep them handy for next time.
After you have created or selected a Debug Level, you can Save the trace flag and voila, it's there. Now for the time duration you specified, you can log as many debug logs as you want without taking stress of running out of them and using them wisely if you are a lazy developer like me.
Not so fast Hot Shot!! There is still 50MB org wide limit with 2MB per log limit enforced. And the expiration time of 24 hours for the logs.
Now coming to Developer Console, you can setup the Trace Flags and Debug Levels here as well. Open the Developer Console as usual and go to Debug => Change Log Levels....
Here you can you can do everything that we did in Salesforce Setup i.e. add Trace Flags and create/modify Debug Levels. The Apex Class trace flag you are seeing in the screenshot in red has expired.
Now coming to why Apex Class and Apex Triggers don't produce any debug logs. These trace flags are just there to specify the log levels for that particular Class and Trigger.
So if you want to see debug logs for a particular Class in Finest log level for any log category, you need to add 2 Trace Flags, one for the user running the class, other for the Apex Class in question.
That's all folks.
----------------------------------------------------------------------------------------------
This is the first article in the "So you want to learn" series guys. If you want to learn about something specific in Salesforce, please comment on this post. I will try to come back with an article on it.
@ Capgemini | M.Tech, Salesforce Lightning Developer/Lead/emerging Architect
8 年Atul , thanks for the nice article. Now I could see the User logs. I added class , trigger trace logs. I have system.debug statement. I couldn't see the class , trigger logs. What should I do?