26

Delete all option in Debug log deletes the log page-wise. Is there any option to delete all the logs in debug at an instance?

DOMINIC EDWARD
  • 1,339
  • 2
  • 17
  • 32

14 Answers14

54

Now that we have SFDX, I use the below method to delete debug logs from terminal:

$ sfdx force:data:soql:query -t -q "SELECT Id FROM ApexLog" -r "csv" > out.csv
$ sfdx force:data:bulk:delete -s ApexLog -f out.csv

Here is sf version of it:

echo "Id" > temp.csv; \
sf apex list log --json | jq -r '.result[].Id' >> temp.csv && \
sf data delete bulk --sobject ApexLog --file temp.csv --wait 1000
javanoob
  • 8,867
  • 14
  • 75
  • 138
  • 3
    Amazing, worked like a charm. Long live Salesforce DX! – Alberto Ojedo Dec 11 '19 at 16:06
  • Better than every option on here. – thinker Dec 13 '19 at 15:06
  • Why it continuously says InvalidBatch : Records not found when I check the status? – Aditya Vijay Feb 04 '20 at 08:10
  • 3
    @AdityaVijay when you run check status command, it might be running against different org. Make sure to pass —targetusername argument – javanoob Feb 04 '20 at 13:00
  • 1
    @javanoob i am getting error taking this approach. After starting delete job i check for job status and i get:

    stateMessage: InvalidBatch : Records not found

    Any idea why this is happening? Btw. this would be the cleanest solution i've seen so far. Thanks!

    – Nikola Naumovski Apr 05 '20 at 11:06
  • 3
    For Windows users that struggle with this solution - PowerShell creates files in utf16-le that Salesforce bulk API doesn't understand. I use this instead: sfdx force:data:soql:query -q "SELECT Id FROM ApexLog" -r "csv" | out-file -encoding utf8 out.csv – Artur Jul 29 '20 at 09:44
  • @Artur this gives the file encoding as utf8-bom, not utf8, which still says invalid batch. I tried to find downloading the file as utf8 but I didn't get any. I added an answer here https://stackoverflow.com/a/63900678/1298013 – Aditya Vijay Sep 15 '20 at 11:29
  • I hit the "InvalidBatch : Records not found" error too. The "output in UTF8" solution got close, then I loaded the file in vim, ran ":set nobomb" and saved it, and now I had a clean UTF8 file to use, which worked. – Jonathan Rupp Sep 15 '20 at 19:10
  • @AdityaVijay I started having inconsistent results myself which depend on the context. Anyway, -encoding ascii did the trick. – Artur Sep 16 '20 at 10:22
  • Followed steps and finally got "Bulk Delete... done" message in command line. But nothing got deleted. Any idea why? btw I am pointing to correct org. – SFDC Dev 27 Oct 29 '20 at 15:05
  • This would make a perfect candidate for a VSCode Task – Robs Oct 31 '20 at 13:56
  • Worked great! Note that as of this writing I cannot do SELECT Id FROM ApexLog in developer console query window anymore, even with tooling api checkbox checked. – skycafe Apr 08 '22 at 08:58
34

SELECt ID from APEXLOG and run this query in DC Query Editior and select the tooling API checkbox. Now Delete all the records. It will solve your problem and this is a native solution.

Tushar Sharma
  • 29,515
  • 7
  • 36
  • 60
  • DC = Developer Console on the username drop down for those that are confused – TemporaryFix Oct 01 '19 at 16:53
  • 1
    did not work for me, instead I got many alerts telling "invalid cross reference id". Any idea what could be going wrong? – SFDC Dev 27 Oct 29 '20 at 15:03
  • That's only because when the exact row is getting deleted in the backend, the query result is not refreshed. So you might have selected the row again and clicked to delete, causing the alerts telling "invalid cross reference id". – Plymouth Rock May 18 '22 at 12:35
14

I had an org with over 400mb of logs that needed to be cleared! The Salesforce developer tools only lets you delete 2000 rows at a time and the process has to be manually repeated.

So instead I opened up Salesforce classic debug log page and run the following JavaScript from Chrome Developer Tools - it will keep bashing the Delete All button for you.

setInterval(
    function() {
       if (document.querySelector('span[id*="deleteAllStatus.start"]').style.display === 'none') {document.querySelector('input[value="Delete All"]').click()}
    }
    ,250);
Daniel Sokolowski
  • 1,002
  • 9
  • 17
12

Use apex debugger chrome extensions. There you can select debug size. for example select 5000 and delete all the debugs. Great tool

Chrome extensions

Apex Debugger

Salesforce Coding Utility

Ratan Paul
  • 22,663
  • 13
  • 52
  • 97
  • there seems to be a firefox version now as well: https://salesforce.stackexchange.com/questions/100401/delete-all-in-debug-log – Guy Clairbois May 01 '19 at 10:35
6

I used the dataloader to export and delete all the debug logs. There were over 4K records so this was without a doubt the quickest way to do it. I chose the object ApexLog and used the following query:

SELECT Id, Status, StartTime, LogUser.Name, Operation, DurationMilliseconds, Location, LogLength, Application FROM ApexLog
Jean Grey
  • 87
  • 1
  • 10
5

Cross Posting as this question seems more canonical.

You cannot delete the debug logs natively in Apex code. But you can use Rest DELETE endpoint to delete debug logs.

I have created a utility code to delete debug logs that way, you can refer it.

The only limitation is

  1. It can delete only 100 in 1 iteration(You can use composite API to bulkify it).

  2. It creates a new debug log after execution

     List <Apexlog> loglist = [Select Id from Apexlog limit 100];
    for(Apexlog al: loglist){
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
        + '/services/data/v44.0/sobjects/Apexlog/'+al.Id);
        req.setMethod('DELETE');
        req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
        HttpResponse res = h.send(req);
        System.debug(res.getStatusCode());
    }
    

If you are calling this method from the lightning component, your Session ID wont be api enabled. Thus you have to use named credentials.

src: https://salesforce.stackexchange.com/a/239642/19118

Pranay Jaiswal
  • 35,996
  • 16
  • 75
  • 134
5

In workbench, query for apex log using below query:

  1. SELECT Id FROM ApexLog
  2. Select view as: Bulk CSV
  3. Download the csv file
  4. Then in workbench go to
  5. Data tab -> select delete option
  6. select From file check box
  7. upload the csv file you got from above mentioned query.
  8. Click on next
  9. click on map fields (id)
  10. click the check box:
  11. Process records asynchronously via Bulk API
  12. Verify that the object type is: ApexLog
  13. Click on confirm delete.
3

There is an extension in Google Chrome called the salesforce-tool which helps in deleting all the logs at once. You won't have to click Delete All everytime. It has some other functionalities too.

Mohit Arora
  • 728
  • 6
  • 15
2

I've had success using the Bulk API to rapidly remove the existing ApexLog records.

Steps (that are automated):

  1. Use SOQL to Query all the ApexLog records and get back the Ids
    Select Id from Apexlog
  2. If there are few records, currently less than 400, delete them with one or two calls the the Partner API.
  3. Otherwise, with many records, use the Bulk API to delete them by Id.

I needed to automate this as I'd occasionally come across production orgs with tens of thousands of records that needed to be deleted before a new TraceFlag could be created.

enter image description here

This functionality is available (on Windows) in the FuseIT SFDC Explorer. See Button to delete ALL ApexLog's in an org.

Daniel Ballinger
  • 102,288
  • 39
  • 270
  • 594
2

Open the browser console and execute this

(function() {
    var request = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function() {
        this.addEventListener('load', function() {
        if(document.querySelector('[id$="thetracetable"] tbody tr')){
             document.querySelectorAll('[id$="deleteAll"]')[0].click();
        }
    });
    request.apply(this, arguments);
};
})();
document.querySelectorAll('[id$="deleteAll"]')[0].click();
Aditya Vijay
  • 1,292
  • 10
  • 23
0

From my side When getting this error in console. I tried via dataloader and it works. I extract all the log and from the same csv I execute the delete.

vanessen
  • 2,645
  • 3
  • 37
  • 60
0

You can use sfdx-hardis command to delete all logs of an org

sfdx hardis:org:purge:apexlog

If you are not connected to an org, it will prompt you for one

This command is also available in VsCode SFDX Hardis menu Debugger

enter image description here

Nicolas Vuillamy
  • 3,159
  • 16
  • 37
0

The option for deleting all debug logs I've been using for years and it works perfectly is a Chrome Extension that provides a button called 'Truly, Delete All' on the Setup debug logs page.

It unfortunately works only in classic interface, so if that's not a deal breaker I highly recommend it.

The chrome extension is called: Salesforce advanced Code Searcher.

Notoc
  • 25
  • 5
-1

You can try with salesforce inspector tool

sarah
  • 179
  • 1
  • 4
  • 14
  • 1
    What is this tool? How would you use it to acccomplish this task? Is this perhaps covered by an existing answer? Being detailed in answers is important. – Derek F Mar 10 '23 at 14:42