Salesforce CLI

Delete Debug Logs from Salesforce

Debug Logs are quite important in the development and troubleshooting errors on Salesforce. When the developers test and improve their codes, debugs logs can accumulate rapidly causing storage and performance issues.

In this article, I will show you how to delete debug logs to prevent unnecessary logs from accumulating in your org.

Delete all Debug Logs in Salesforce

How to Delete all Debug Logs

Salesforce CLI (Command Line Interface) offers an efficient solution to retrieve and quick delete all Debug Logs using Visual Studio Code on your project folder.

1. Retrieving Debug Logs with Salesforce CLI:

Salesforce CLI provides a simple command to retrieve Debug Logs. To get started, open your terminal or command prompt, make sure you have Salesforce CLI installed and you are authenticated with your Salesforce org.

Run the following command to retrieve Debug Logs in a csv file into your project folder:

sfdx force:data:soql:query -q "SELECT Id FROM ApexLog" -r "csv" | out-file -encoding oem apexlogs.csv

This is how it looks the new file generated with all the Debug Logs

Retrieve Apex logs from Salesforce into your Visual Studio Code project root folder

2. Clear all the Debug Logs:

Once you have retrieved the Debug Logs, you can delete them by running the following command:

sfdx force:data:bulk:delete -s ApexLog -f apexlogs.csv

This command will create a bulk data load job to delete all the debug logs. You can check the status of your job in Setup > Bulk Data Load Jobs.

Bulk Data Load Job in Salesforce executed by the CLI from Visual Studio Code

Why is it Important to Clear Debug Logs?

As developers continuously test and deploy code, the number of Apex Logs can grow significantly, leading to unnecessary data clutter. Clearing old logs not only helps free up storage space but also ensures a more streamlined process for debugging and monitoring. By regularly managing Apex Logs, you can maintain an organized development environment.