Silly Dev Trick: How to delete the apex debug logs with Use Tooling API

Every year they seem to up the limit but for those doing intensive testing and running up your logs here is a quick way to release the storage:

tl;dr

  • Run the following soql in developer console with the ‘Tooling API’ checked:
    • select id, LogLength, LogUser.Name from apexlog order by LogLength DESC
    • select id, LogLength, LogUser.Name from apexlog WHERE LogUser.Name = 'FirstName LastName' order by LogLength DESC

2022 Update: Added second bullet showing how to add a filter as in busy sandboxes sometimes you just want to delete your logs in bulk.

Long Explanation

You get the following error message:

Having an active trace flag triggers debug logging. You have 1076 MB of the maximum 1000 MB of debug logs. Before you can edit trace flags, delete some debug logs.

Reference: https://help.salesforce.com/articleView?id=code_debug_log_delete.htm&type=5

  • Fire up the developer console
  • Click the ‘Query’ tab and check the ‘Use Tooling API’ on/true
  • Copy/Paste the following soql and hit ‘Execute’
    • select id, LogLength, LogUser.Name from apexlog order by LogLength DESC
  • Select a bunch of the top records using the shift key and then click the ‘Delete Row’ button to delete
  • Now wait…and then hit the ‘Refresh Grid’ button a couple times. If you try to delete a row that has already been selected to be deleted it will throw an error window for EACH record…ouch. So have patience if you are deleting the files in chunks. Once you have deleted refresh the entire window and the logs tab will once again work.

1 Reply to “Silly Dev Trick: How to delete the apex debug logs with Use Tooling API”

  1. Thank you. That was very useful!

    It doesn’t seem that there’s a way to delete the logs in the Query Editor.
    Like Delete from [table] limit 10

    Is that correct?

Leave a Reply

Your email address will not be published. Required fields are marked *