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?
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.
-
DC = Developer Console on the username drop down for those that are confused – TemporaryFix Oct 1 '19 at 16:53
-
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
Now that we have SFDX, I use the below method to delete debug logs from terminal:
$ sfdx force:data:soql:query -q "SELECT Id FROM ApexLog" -r "csv" > out.csv
$ sfdx force:data:bulk:delete -s ApexLog -f out.csv
-
2
-
-
1@AdityaVijay when you run check status command, it might be running against different org. Make sure to pass —targetusername argument – javanoob Feb 4 '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 5 '20 at 11:06 -
1For 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 9:44
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);
-
Please check my answer, doing the same but in a more optimized way :-) – Aditya Vijay Sep 8 '20 at 10:00
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
-
there seems to be a firefox version now as well: salesforce.stackexchange.com/questions/100401/… – Guy Clairbois May 1 '19 at 10:35
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
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
It can delete only 100 in 1 iteration(You can use composite API to bulkify it).
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.
In workbench, query for apex log using below query:
- SELECT Id FROM ApexLog
- Select view as: Bulk CSV
- Download the csv file
- Then in workbench go to
- Data tab -> select delete option
- select From file check box
- upload the csv file you got from above mentioned query.
- Click on next
- click on map fields (id)
- click the check box:
- Process records asynchronously via Bulk API
- Verify that the object type is: ApexLog
- Click on confirm delete.
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.
I've had success using the Bulk API to rapidly remove the existing ApexLog records.
Steps (that are automated):
- Use SOQL to Query all the ApexLog records and get back the Ids
Select Id from Apexlog
- If there are few records, currently less than 400, delete them with one or two calls the the Partner API.
- 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.
This functionality is available (on Windows) in the FuseIT SFDC Explorer. See Button to delete ALL ApexLog's in an org.
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();
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.