---
schema_version: "1"
id: d185fece73d7336be0875cbddb392140d283ffdb0d29b204b1ef0a6028f01647
title: Set Up Apex Class and Trigger Trace Flags
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_setup.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.code_debug_log_classes_setup.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 4e4805b3d25b134bc85eb53e73405589ce829664d9cfa90def184f15e8207d0c
description: 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.
products:
  - Salesforce Platform
release: "264"
---
# Set Up Apex Class and Trigger Trace Flags

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.

### 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_setup__Apex_Code_editions_text"><a name="code_debug_log_classes_setup__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>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d35974e82">User Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">To use the Developer Console:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">API Enabled AND View All Data</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">To view, retain, and delete debug logs:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">View All Data</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">To execute anonymous Apex: </td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">Author Apex</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">To save changes to Apex classes and triggers:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">Author Apex</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">To use Salesforce CLI and run Tooling API queries:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d35974e82 ">API Enabled</td>

          </tr>
        </tbody>
      </table>

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

Tip For an applied example of using Apex class and trigger trace flags, see [Debug Log Filtering for Apex Classes and Apex Triggers](https://help.salesforce.com/s/articleView?id=platform.code_debug_log_classes.htm&release=264.0.0&type=5 "Debug log filtering provides a mechanism for fine-tuning the log verbosity at the trigger and class level.").

## Create Apex Class and Trigger Trace Flags in Setup

![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 Although you can set up an Apex class or trigger trace flag in Setup, these trace flags don’t appear in the log list on the Debug Logs page. The page shows only `USER_DEBUG` and `DEVELOPER_LOG` log types, not `CLASS_TRACING` log types. You can still access `CLASS_TRACING` log types created in Setup from the Apex class or trigger’s Setup page, from the Developer Console, or with Tooling API.

1. From Setup, enter Debug Logs in the Quick Find box, and then click **Debug Logs**.
2. Click **New**.
3. For Traced Entity Type, select **Apex Class** or **Apex Trigger**.
4. For Traced Entity Name, enter the name of the Apex class or trigger that you want to add a trace flag to.
5. To define a time period during which the trace flag is active, enter a Start Date and an Expiration Date.
6. To set a debug level profile, either enter the name of a debug level profile that you’ve already defined, or click **New Debug Level**.
    
    If you click **New Debug Level**, a new window opens. To define a new debug level profile, in the new window, enter a name for the debug level profile. Then select a debug log level for each debug log category. Save your changes.
7. Save the trace flag.

## View, Edit, or Delete Apex Class and Trigger Trace Flags in Setup

1. Navigate to the appropriate Apex class or trigger Setup page.
    1. For Apex class trace flags, from Setup, enter Apex Classes in the Quick Find box, and then click **Apex Classes**.
    2. For Apex trigger trace flags, from Setup, enter Apex Triggers in the Quick Find box, and then click **Apex Triggers**.
2. Click the name of the Apex class or trigger that you want to examine.
3. Click the desired option.
    1. To create a trace flag, click **New**. Then enter a start date, an expiration date, and a debug level profile for the trace flag.
    2. To delete a trace flag, in the trace flag’s Action column, click **Delete**.
    3. To modify a trace flag’s start date, expiration date, or debug level profile, click **Edit**.
    4. To modify a trace flag’s debug levels, click **Filters**. Then select the desired debug level for each category.
    5. To delete all trace flags for the Apex class or trigger, click **Delete All**.
4. Save your changes.

## Create Apex Class and Trigger Trace Flags in the Developer Console

1. From the Developer Console, click **Debug | Change Log Levels…**.
    
    ![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)
2. In the Class and Trigger Trace Overrides section, click **Add**.
3. Select the class or trigger that you want to add a trace flag to.
4. To define a time period during which the trace flag is active, click the Start Date cell for the class or trigger, and then enter or select a valid start time. Then click the Expiration Date cell and enter or select a valid end time.
5. To set a debug level profile, click **Add/Change** in the DebugLevel Action cell for the class or trigger. Then perform one of these actions.
    
    1. To set the debug level to a debug level profile that you already defined, click the name of the debug level profile so that its row is highlighted. Then click **Done**.
    2. To adjust the debug levels of a debug level profile that you already defined, click the name of the debug level profile so that its row is highlighted. Select a new debug level from the dropdowns for each debug log category that you want to adjust. Then click **Done**.
    3. To add a new debug level profile, click **Add**. In the new window, enter a DebugLevel Name. Then select a debug level from the dropdowns for each debug log category. Click **Add**, and then click **Done**.
    4. To delete a debug level profile, click the name of the debug level profile, and then click **Remove**. Then click **Done**.
        
        Warning: This action removes the debug log profile from all of its assigned 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)

## Create Apex Class and Trigger Trace Flags Using Salesforce CLI Commands

![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 Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.

1. If you don’t have an existing debug level profile that you want to use, first create a [DebugLevel](https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_debuglevel.htm) record with Tooling API by using the [`sf data create record`](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_create_record_unified) command. Replace the placeholder values with the desired name of the debug level profile and the desired debug level for each debug log category.
    
    ```
    sf data create record --use-tooling-api --sobject DebugLevel --values "DeveloperName='DEBUG_LEVEL_PROFILE_NAME' MasterLabel='DEBUG_LEVEL_PROFILE_NAME' Workflow='FINER' ApexCode='FINE' System='DEBUG' Validation='INFO' Database='INFO' Callout='INFO' Visualforce='INFO' ApexProfiling='INFO'"
    ```
2. Get the `DebugLevel` record ID for the debug level profile by using the [`sf data query`](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_query_unified) command. Replace the placeholder value with the `DeveloperName` of the debug level profile.
    
    ```
    sf data query --query "SELECT Id FROM DebugLevel WHERE DeveloperName='DEBUG_LEVEL_PROFILE_NAME'"
    ```
3. Get the ID of the Apex class or trigger that you want to trace by using the [`sf data query`](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_query_unified) command. Replace the placeholder value with the name of the Apex class or trigger.
    
    ```
    sf data query --query "SELECT Id FROM ApexClass WHERE Name='APEX_CLASS_NAME'" 
    ```
4. Create a [`TraceFlag`](https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_traceflag.htm) record with Tooling API. Replace the placeholder values.
    
    ```
    sf data create record --use-tooling-api --sobject TraceFlag --values "TracedEntityId='APEX_CLASS_OR_TRIGGER_ID' DebugLevelId='DEBUG_LEVEL_ID' LogType='CLASS_TRACING' StartDate='START_TIME_UTC' ExpirationDate='END_TIME_UTC'"
    ```
5. If you haven’t already, create another `TraceFlag` record on the user whose actions you want to trace. Apex class or trigger trace flags don’t generate debug logs on their own.
    
    ```
    sf data create record --use-tooling-api --sobject TraceFlag --values "TracedEntityId='USER_ID' DebugLevelId='DEBUG_LEVEL_ID' LogType='USER_DEBUG' StartDate='START_TIME_UTC' ExpirationDate='END_TIME_UTC'"
    ```

To work with debug logs, use these commands:

- To fetch the specified log or given number of most recent logs from the org, use the [`apex get log`](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm#cli_reference_apex_get_log_unified) command.
- To display a list of IDs and general information about debug logs, use the [`apex list log`](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm#cli_reference_apex_list_log_unified) command.
- To activate a debug log for the current user and stream the debug log to the console, use the [`sf apex tail og command`](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_apex_commands_unified.htm#cli_reference_apex_tail_log_unified).

#### 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)
- [Debug Log Filtering for Apex Classes and Apex Triggers](https://help.salesforce.com/s/articleView?id=platform.code_debug_log_classes.htm&release=264.0.0&type=5 "Debug log filtering provides a mechanism for fine-tuning the log verbosity at the trigger and class level.")
- [_Salesforce DX Developer Guide_: Generate and View Apex Debug Logs](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_develop_view_apex_debug_logs.htm)
- [_Apex Developer Guide_: Debugging Apex](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging.htm)