Share Your Experience With Others

How to Delete Debug Logs Using Code

List<ApexLog> logLst=[Select Id from ApexLog limit 100];

for(ApexLog log:logLst){
	Http h=new Http();
	HttpRequest req=new HttpRequest();
	req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()+'/services/data/v56.0/sobjects/ApexLog/'+log.Id);
	req.setMethod('DELETE');
	req.setHeader('Authorization','Bearer '+UserInfo.getSessionId());
	HttpResponse res=h.send(req);
	System.debug('Get Status Code '+res.getStatusCode());

}

Use this code in anonymous window. This code will work with limit 100. You can try for more than 100 records and share the response.

or use this query in Developer Console:

Select id from ApexLog

Select multiple rows and click Delete Row

Leave a comment