---
schema_version: "1"
id: 3612bc44515e4dfd30ac8ab8e5bb4222dea6c0bbd6466891d2e91121d1f4b505
title: Debug Log Filtering for Apex Classes and Apex Triggers
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/code_debug_log_classes.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.code_debug_log_classes.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: e154f757d77806ccc7dfa9f75e72cb6f99a696001d76a6d9e4b740cab96683da
description: Debug log filtering provides a mechanism for fine-tuning the log verbosity at the trigger and class level.
products:
  - Salesforce Platform
release: "264"
---
# Debug Log Filtering for Apex Classes and Apex Triggers

Debug log filtering provides a mechanism for fine-tuning the log verbosity at the trigger and class level.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Salesforce Classic (<a href="https://help.salesforce.com/s/articleView?id=xcloud.overview_edition_lex_only.htm&amp;language=en_US" target="_blank">not available in all orgs</a>) and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <span id="code_debug_log_classes__Apex_Code_editions_text"><a name="code_debug_log_classes__Apex_Code_editions_text"></a><strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, <strong>Developer</strong>, and <strong>Database.com</strong> Editions</span></td></tr></tbody></table>

To debug complex Apex logic, you can set Apex class and trigger trace flags, also known as debug log filters. For example, you can raise the log verbosity for a given class while turning off logging for other classes or triggers. These trace flags have the debug log type `CLASS_TRACING` and override the debug log levels of the `USER_DEBUG` and `DEVELOPER_LOG` trace flags.

When you override the debug log levels for a class or trigger, these debug log levels also apply to the class methods that your class or trigger calls and the triggers that get executed as a result. All class methods and triggers in the execution path inherit the debug log settings from their caller, unless they have their own trace flags that override these settings.

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_important.png)

Important Apex class and trigger trace flags don’t generate logs on their own. Logging occurs only if either the `USER_DEBUG` or the `DEVELOPER_LOG` trace flag is active for the user running the code.

For concrete instructions about how to configure debug log filters, see [Set Up Apex Class and Trigger Trace Flags](https://help.salesforce.com/s/articleView?id=platform.code_debug_log_classes_setup.htm&release=264.0.0&type=5 "You can set up an Apex class or trigger trace flag in Salesforce Setup, in the Developer Console, or by creating Tooling API objects with Salesforce CLI commands. These trace flags have the CLASS_TRACING debug log type and override the debug log levels of the USER_DEBUG and DEVELOPER_LOG trace flags.").

## Example of Fine-Tuned Debug Logging

Let’s explore how Apex class and trigger trace flags override the debug log levels of other trace flags.

First, define these example classes and triggers: `Class1`, `Class2`, `Class3`, `UtilityClass`, `Trigger1`, and `Trigger2`.

```java
public with sharing class Class1 {
    public static void class1Method() {
        System.debug('Class1.class1Method() was called');
        Class3.class3Method();
    }
}
```

```java
public with sharing class Class2 {
    public static void class2Method() {
       // Code that invokes Trigger2
        System.debug('Class2.class2Method() was called');
        Contact newContact = new Contact(FirstName='FirstName', LastName='LastName');
        insert newContact;
    }
}
```

```java
public with sharing class Class3 {
    public static void class3Method() {
        System.debug('Class3.class3Method() was called');
        UtilityClass.utilityMethod();
    }
}
```

```java
public with sharing class UtilityClass {
    public static void utilityMethod() {
        System.debug('UtilityClass.utilityMethod() was called');
    }
}
```

```java
trigger Trigger1 on Account (before insert) {
    System.debug('Trigger1 invoked');
    Class1.class1Method();
    Class2.class2Method();
}
```

```java
trigger Trigger2 on Contact (before insert) {
  System.debug('Trigger2 invoked');
}
```

Here’s a summary of how this code runs.

- `Trigger1` fires before a new account is inserted.
- `Trigger1` calls `Class1.class1Method()` and `Class2.class2Method()`.
- The `Class1.class1Method()` calls `Class3.class3Method()`, which in turn calls the `UtilityClass.utilityMethod()` method.
- The `Class2.class2Method()` inserts a new contact, which invokes `Trigger2`

Now, let’s first examine a debug log for this code without any class or trigger trace flag overrides. To invoke `Trigger1`, in an Anonymous Apex code block, create and insert a new account.

```java
Account newAccount = new Account(Name='Test Account 1234');
insert newAccount;
```

If you execute an Anonymous Apex code block in the Developer Console, the `DEVELOPER_LOG` trace flag is active, and the `SFDC_DevConsole` debug log level profile is applied by default. The `SFDC_DevConsole` debug log level profile has these debug log levels set.

- Apex Code—Finest
- Apex Profiling—Info
- Callouts—Info
- Data Access—Info
- Database—Info
- NBA—Info
- System—Debug
- Validation—Info
- Visualforce—Finer
- Wave—Info
- Workflow—Info

Here’s a snippet of the debug log in the Developer Console. The Debug Only filter is applied, so only [`USER_DEBUG`](https://help.salesforce.com/s/articleView?id=platform.code_setting_debug_log_levels.htm&type=5&language=en_US) events are shown.

```
13:40:23.49 (477255762)|USER_DEBUG|[2]|DEBUG|Trigger1 invoked
13:40:23.49 (490847713)|USER_DEBUG|[3]|DEBUG|Class1.class1Method() was called
13:40:23.49 (501554543)|USER_DEBUG|[3]|DEBUG|Class3.class3Method() was called
13:40:23.49 (513291355)|USER_DEBUG|[3]|DEBUG|UtilityClass.utilityMethod() was called
13:40:23.49 (527535070)|USER_DEBUG|[4]|DEBUG|Class2.class2Method() was called
13:40:23.49 (570470421)|USER_DEBUG|[2]|DEBUG|Trigger2 invoked
```

Because the Apex Code debug log level is `FINEST`, all `System.debug()` statements invoked from Apex classes or triggers are written to the debug log.

Now, to demonstrate class and trigger trace flag overrides, let’s change the debug log levels according to this scenario.

- Suppose `Class1` is causing some issues that you want to examine closely. You create a `Class1` trace flag that raises the debug log levels of `Class1` to the finest granularity.
- Because `Class1` calls `Class3`, `Class3` inherits the granular log filters of `Class1`. `Class3` calls `UtilityClass`, but suppose you’ve already tested `UtilityClass` and confirmed that it works properly. Therefore, you create a `UtilityClass` trace flag where all the log filters are turned off.
- Similarly, `Class2` isn’t in the code path that causes a problem, so you create a `Class2` trace flag where logging is minimized to log only errors for the Apex Code category. Because `Class2` invokes `Trigger2`, `Trigger2` inherits the log level settings of `Class2`.

This diagram illustrates the new debug log levels in this scenario.

**Fine-tuning debug logging for classes and triggers**

![Debug log filters for classes and triggers](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/extend_code/images/debug_log_class_filtering.png)

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_note.png)

Note

In the diagram, `Trigger1` shows the [default log levels](https://help.salesforce.com/s/articleView?id=platform.code_debug_log_precedence.htm&type=5&language=en_US) without any active trace flags. When working in the Developer Console, the `DEVELOPER_LOG` trace flag is active by default, so the debug logs in this example reflect the `SFDC_DevConsole` debug log level profile instead.

Here’s how the Developer Console appears after you create debug log level profiles and assign them to class or trigger trace flags.

![The Change DebugLevel window in the Developer Console, where you can create and modify debug log level profiles.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/extend_code/images/debug_log_class_change_debug_level.png)

![The Change Log Levels window in the Developer Console, where you can set debug trace flags.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/extend_code/images/debug_log_class_filtering_change_log_levels.png)

Now, execute the Anonymous Apex code block again.

If you open the debug log and filter by Debug Only, you can see that the class and trigger trace flag overrides are applied.

```
15:29:49.42 (65879589)|USER_DEBUG|[2]|DEBUG|Trigger1 invoked
15:29:49.42 (68318473)|USER_DEBUG|[3]|DEBUG|Class1.class1Method() was called
15:29:49.42 (69855182)|USER_DEBUG|[3]|DEBUG|Class3.class3Method() was called
```

`Trigger1` retains the default `SFDC_DevConsole` debug log level profile because it doesn’t have an active trigger trace flag override. Therefore, its `System.debug()` message still appears in the debug log.

The debug log level of `Class1` and `Class3` for the Apex Code category is set to `FINEST`, so the `System.debug()` statements in the called methods of these classes are shown.

The debug log level of `Class2` and `Trigger2` for the Apex Code category is set to `ERROR`, which means that only errors and exceptions are logged. If the `System.debug()` [`LoggingLevel` enum](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_System_LoggingLevel.htm) is set to `ERROR`, then `System.debug()` messages in these classes are also logged. However, in this case, the `System.debug()` logging level remains at the default `DEBUG` level. Therefore, the `System.debug()` method in the called methods of these classes aren’t logged.

Finally, the debug log level of `UtilityClass` for the Apex Code category is set to `NONE`, which means that no debug logs are generated when methods from this class are called.

#### See Also

- [Set Up Debug Logging](https://help.salesforce.com/s/articleView?id=xcloud.code_add_users_debug_log.htm&type=5&language=en_US)
- [Set Up Apex Class and Trigger Trace Flags](https://help.salesforce.com/s/articleView?id=platform.code_debug_log_classes_setup.htm&release=264.0.0&type=5 "You can set up an Apex class or trigger trace flag in Salesforce Setup, in the Developer Console, or by creating Tooling API objects with Salesforce CLI commands. These trace flags have the CLASS_TRACING debug log type and override the debug log levels of the USER_DEBUG and DEVELOPER_LOG trace flags.")
- [Debug Log Levels](https://help.salesforce.com/s/articleView?id=platform.code_setting_debug_log_levels.htm&release=264.0.0&type=5 "To specify the level of information that gets included in debug logs, set up trace flags and debug levels. The debug levels assigned to your trace flags control the type and amount of information that is logged for different events. After logging has occurred, inspect debug events in your debug logs.")