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?

Hello,

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!

Thanks
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.

Thanks
 
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: https://help.salesforce.com/articleView?id=000333120&type=1

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:

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

https://salesforce.stackexchange.com/questions/239636/how-to-delete-all-debug-apex-logs-in-apex

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.

Thanks!