Idan Bliech
2 min readFeb 6, 2023
TraceFlag in Salesforce

Trace Flags in Salesforce are a powerful tool for developers to debug, troubleshoot and analyze the performance of Apex code. They allow developers to capture the execution context of Apex code and track its performance in real-time. In this blog post, we will discuss how to delete Trace Flags using SFDX (Salesforce Development Experience) for Salesforce developers.

What is a Trace Flag?

A Trace Flag is a special setting in Salesforce that captures detailed information about the execution of Apex code. It records various events, such as the execution of Apex methods, SOQL queries, and DML operations, and writes them to a log file. Developers can then use this log file to analyze the performance of their code and identify any issues or bottlenecks. Trace Flags can be enabled for a specific user, set of users, or for the entire organization.

Where to use Trace Flags?

Trace Flags are commonly used for debugging and troubleshooting Apex code in the following scenarios:

  1. Debugging Apex code — Trace Flags help developers identify and resolve issues with Apex code by providing a detailed log of its execution.
  2. Analyzing performance — Trace Flags allow developers to monitor the performance of Apex code and identify any bottlenecks or inefficiencies.
  3. Debugging issues with integrations — Trace Flags can be used to debug issues with integrations between Salesforce and other systems.

Deleting Mass Trace Flags ?

Use SFDX To delete a Trace Flag using SFDX execute the follow code in your terminal

#!/bin/bash

myAlias=<fill your alias here>

for row in $(sfdx force:data:soql:query -q "SELECT Id FROM TraceFlag" --usetoolingapi --resultformat "json" | jq -r '.result.records | .[].Id' )
do
echo sfdx force:data:record:delete --sobjecttype TraceFlag --sobjectid ${row} --targetusername ${myAlias}
sfdx force:data:record:delete --usetoolingapi --sobjecttype TraceFlag --sobjectid ${row} --targetusername ${myAlias}
done

In conclusion, Trace Flags are an essential tool for Salesforce developers to debug, troubleshoot and analyze the performance of Apex code. By using SFDX, developers can delete Trace Flags efficiently and effectively. Understanding how to use Trace Flags and how to delete them using SFDX is an important skill for Salesforce developers to master.

🚩🚩 My Latest App is now on the AppExchange
Viewer for Document Generator. This app is based on word template, it includes unlimited users and unlimited templates and unlimited automation. Here is the link:
https://4winds.link/VIewerLP