Author: Vishal Lala
Getting bugs while developing is common, but reviewing and debugging them takes one of a time. So in this blog, we will learn how to visualize salesforce logs, either it is from Apex or any process running or logging errors or any audit changes using different logs like Debug Logs, Audit Logs, etc.
What is a Trace Flag?
Before moving ahead with debug logs, we need to understand what a Trace Flag is and how we set it up.
Trace Flag helps salesforce to trace any execution performed by a user and helps to generate logs. Each trace flag includes a debug level, start time, end time, and log type.
How to Set Up a Trace Flag
- Go to Setup.
- In the Quick Find, search Debug Logs and click it.
- In the User Trace Flags section, click New.
- In the Trace Entity Name lookup, choose a User. And select a Start Date, Expiration Date, choose a Debug Level, or create one.
- Hit the Save button.
Note: Trace Entity Type can be of User, Class, Trigger, Automated Process, or Platform Integration, depending upon your use case.
A trace flag includes a debug level, a start time, an end time, and a log type. A debug level is a set of log levels for debug log categories, such as Database, Workflow, and Validation. The log types are DEVELOPER_LOG, USER_DEBUG, and CLASS_TRACING.
|Database||DML statement or inline SOQL or SOSL query.|
|System||Information about System Methods calls like System.debug() method.|
|Apex Code||Includes information about Apex code. Can include information such as log messages generated by DML statements, inline SOQL or SOSL queries, the start and completion of any triggers, and the start and completion of any test method.|
|Workflow||Includes information for workflow rules, flows, and processes, such as the rule name and the actions taken.|
|Validation||Includes information about validation rules, such as the name of the rule and whether the rule evaluated true or false.|
|Callout||Includes the request-response XML that the server is sending and receiving from an external web service. Useful when debugging issues related to using Lightning Platform web service API calls or troubleshooting user access to external objects via Salesforce Connect.|
|Apex Profiling||Includes cumulative profiling information, such as the limits for your namespace and the number of emails sent.|
|Visualforce||Includes information about Visualforce events, including serialization and deserialization of the view state or the evaluation of a formula field in a Visualforce page.|
|NBA||Includes information about Einstein Next Best Action activity, including strategy execution details from Strategy Builder.|
Each debug level includes one of the following log levels for each log category. The levels are listed from lowest to highest. Specific events are logged based on the combination of category and levels. Most events start being logged at the INFO level. The level is cumulative, that is, if you select FINE, the log also includes all events logged at the DEBUG, INFO, WARN, and ERROR levels.
Let’s say you want to have FINER info about your System.log(‘Your Debug Statement’), but your default level for System Category is set up to WARN, so you can override it by using:
System.debug(LoggingLevel.FINER, ‘Your Debug Statement’);
Debug logs are used to track the events information that happens in your Org. Logs can contain data about different Log Categories listed in the above section.
You can use debug logs to analyze your call stack, errors, performance issues, and many other things.
You can choose different Perspectives in the debug log to see different detailed sections.
Structure of a Debug Log
- 1st line in Debug log is Header and it defines information about your Version Information and Log Categories with their respective Log Levels.
- 2nd line is about User Information.
21:32:55.0 (576594)|USER_INFO|[EXTERNAL]|0055g00000BQ0w7firstname.lastname@example.org|(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)|GMT-07:00 21:32:55.0 (649313)|EXECUTION_STARTED
- From the 3rd line onwards it shows information about your Execution.
- Last line display that the Execution has ended.
A debug log line consists of Timestamp (Number of Nanoseconds since the transaction started)+ Event Identifier.
Setup Audit Trail
Setup Audit Trails helps us analyze all the changes made into the Org, be it creating a user, creating a field, modifying apex classes and processes, etc.
One of the great use cases is to see the changes or track the details of changes that have been done in the org when you are working in a multi-user environment.
Setup Audit logs have data only up to the last 6 months. To see setup audit trails, go to setup and search View Setup Audit Trail.
Email Logs helps review all the emails sent from the salesforce org and check the status for it, like whether that was successful or not.
To get the emails logs,
- Go to setup and in Quick Find, search for Emails Logs Files.
- Click Request an Email Log.
Email logs will only store the last 30 days’ emails details.