Unlocking the Hidden Power of Salesforce Debug Log Management

Kushal Basu
2 min readMay 21, 2023

🌟 Unlocking the Hidden Power of Salesforce Debug Log Management

Attention Salesforce Admins and Developers! I have a little secret to share that will simplify your life and boost your productivity. 🤫✨ Imagine a world where managing Apex debug logs becomes effortless. No more tedious manual deletions, just a clever trick to save you time and frustration. Let me unveil this hidden gem! 💎💡

Behold, the magic command:

sfdx data query -q “SELECT id FROM ApexLog” — result-format csv > debuglogs.csv

sfdx force data bulk delete -s ApexLog -f debuglogs.csv

Here’s how it quietly works its wonders: 🤐🔮

Step 1: Capturing the Culprits
Execute the first command, and like a skilled wizard, it discreetly queries your Salesforce org, capturing the IDs of all those bothersome Apex debug logs. To keep things covert, it gently saves the results in a file named “debuglogs.csv”. 🧙‍♂️✉️

Step 2: The Grand Finale
Prepare for the grand finale! The second command, operating behind the scenes, calls upon the mighty Salesforce CLI. It gracefully initiates a stealthy bulk deletion operation, relying on the file you created to perform its vanishing act. 🌙🚀

Witness the magic unfold as your org becomes decluttered, and your debugging process becomes a breeze. ✨💪

Now, let’s dive a bit deeper into the magic and understand how this technique works. The first command leverages the Salesforce CLI’s data query feature. It allows you to execute a SOQL query directly from your command line interface. By running the specified query (`SELECT id FROM ApexLog`) and setting the result format as CSV, you retrieve the IDs of all Apex debug logs in your org. These IDs are then conveniently saved in the “debuglogs.csv” file.

Next, armed with the IDs of the debug logs, the second command employs the force data bulk delete feature of the Salesforce CLI. By specifying the object to delete (`ApexLog`) and providing the path to the CSV file containing the IDs (`debuglogs.csv`), the Salesforce CLI takes charge and efficiently performs the bulk deletion, eliminating the debug logs that were causing clutter and consuming unnecessary storage space.

Remember, the greatest secrets are meant to be shared discreetly. Feel free to pass on this tip to your fellow Salesforce enthusiasts, and let them uncover the hidden power of this technique. 🤫💌

By embracing this trick, you’ll streamline your debugging process, reclaim valuable storage space, and boost your productivity as a Salesforce Admin or Developer. Say goodbye to manual deletions and hello to a more efficient way of managing Apex debug logs.

Give it a try and unlock the hidden potential of Salesforce Debug Log Management. Happy coding! ✨🚀

--

--

Kushal Basu

Tech Enthusiast Salesforce Developer Sr. Technical Consultant @ Salesforce