Apisero is now part of NTT DATA - Learn more.

Close this search box.

Debugging Salesforce Using Logs

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

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
  1. Go to Setup.
  2. In the Quick Find, search Debug Logs and click it.
  3. In the User Trace Flags section, click New.
  4. In the Trace Entity Name lookup, choose a User. And select a Start Date, Expiration Date, choose a Debug Level, or create one.
  5. Hit the Save button.

Note: Trace Entity Type can be of User, Class, Trigger, Automated Process, or Platform Integration, depending upon your use case.

Debug Levels

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.

Log Category
Log CategoriesDetails
DatabaseDML statement or inline SOQL or SOSL query.
SystemInformation about System Methods calls like System.debug() method.
Apex CodeIncludes 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.
WorkflowIncludes information for workflow rules, flows, and processes, such as the rule name and the actions taken.
ValidationIncludes information about validation rules, such as the name of the rule and whether the rule evaluated true or false.
CalloutIncludes 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 ProfilingIncludes cumulative profiling information, such as the limits for your namespace and the number of emails sent.
VisualforceIncludes information about Visualforce events, including serialization and deserialization of the view state or the evaluation of a formula field in a Visualforce page.
NBAIncludes information about Einstein Next Best Action activity, including strategy execution details from Strategy Builder.
Log Level

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.

  • NONE
  • WARN
  • INFO
  • FINE

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

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]|0055g00000BQ0w7|vishalacme@apisero.com|(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.

21:32:55.0 (649313)|EXECUTION_STARTED

  • Last line display that the Execution has ended.

21:33:07.11 (12022715735)|EXECUTION_FINISHED

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

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.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.