function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MarkLMarkL 

Mass Delete ApexLog objects (not from the Developer Console)?

Is there any way to mass delete ApexLog objects that is not from the developer console? When you have around 800 of them the developer console takes forever to delete them and it looks like ApexLog objects can't be deleted via SOQL calls in APEX, so what's the alternative to sitting for 5 minutes waiting for my logs to clear off of a half frozen developer console?
Best Answer chosen by MarkL
Khan AnasKhan Anas (Salesforce Developers) 
Hi Mark,

Greetings to you!

You can use dataloader to export and delete all the debug logs. Also, there are some chrome extensions like Apex Debugger (https://chrome.google.com/webstore/detail/apex-debugger/mpckkbblhbfngaininanfjpdfjhbncjo?hl=en) which will help you in deleting logs.

Please refer to the below link which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/100401/delete-all-in-debug-log

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Mark,

Greetings to you!

You can use dataloader to export and delete all the debug logs. Also, there are some chrome extensions like Apex Debugger (https://chrome.google.com/webstore/detail/apex-debugger/mpckkbblhbfngaininanfjpdfjhbncjo?hl=en) which will help you in deleting logs.

Please refer to the below link which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/100401/delete-all-in-debug-log

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Raj VakatiRaj Vakati
Yes .. Refer this lilnk 


https://help.salesforce.com/articleView?id=000194045&language=en_US&type=1


 
Raj VakatiRaj Vakati
Please refer this code and you can able to delete by using tooling REST API or SOAP API
https://salesforce.stackexchange.com/questions/239636/how-to-delete-all-debug-apex-logs-in-apex
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());
}

System.debug('loglist'+loglist);

 
MarkLMarkL
Thanks Khan and Raj

Data Loader seems to work fine but is a bit roundabout.

The code Raj posted works well but only works for 100 logs at a time and this limit doesn't seem to go away when running the code via batch apex. Is there an easier way to get this to clear ~800 logs at a time quickly?
Naveen KNNaveen KN
We can delete debug logs using
1.    Debug logs view from the Salesforce setup
2.    Developer console
3.    Workbench

more details from this article > https://www.codekiat.com/2022/11/how-to-delete-debug-logs-in-salesforce.html