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
NM AdminNM Admin 

DML is not allowing on ApexLog?


I am writting  schedulable batch class to delete the apex logs older than one day but on DML statement its giving error "DML operation Delete not allowed on List<ApexLog>". Can we have other way to schedule the same?

Welcome to your suggestions!

Meghna Vijay 7Meghna Vijay 7
Hi NM,

I don't think it can be done via batch class , all you can do is Use Query Editor of Developer Console and Select Use Tooling API and run
'SELECT Id, StartTime, LogUserId, LogLength, Location FROM ApexLog' to delete those logs.

Khan AnasKhan Anas (Salesforce Developers) 
Hi NM,

Greetings to you!

As mentioned by Meghna, you cannot delete the debug logs in Apex code. You can delete it using Tooling API:

Alternatively, you can use REST to delete debug logs or you can use apex debugger chrome extensions.

Please refer to the below links for more information:

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
NM AdminNM Admin
@Meghna, Khan Anas 

Thanks for quick response on the same.

Yes, we can do this from developer console. Still if you find something that meets the requirement you can share.