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
sdusdu 

Why debug logs get deleted automatically?

I am trying to debug my app. It's a batch process so there should be several logs and I need to find info in one of the logs. But somehow, only the most recent 2 (or 4) logs are kept, earlier ones disappears right away. Anyone knows why? 
Suraj GharatSuraj Gharat

Apex Batch may execute several transacions within few seconds and each transaction gets its own debug log. When we add a user to monitor his debug log, Salesforce records debugs for him for only 20 transactions. When the batch ran, Salesforce must have recorded its first 20 executions and then it stopped, hence you didnt notice all debug logs. But you got 2-3 recent logs, this may be because you must have clicked "Reset" button to refresh debug log page, and "Reset" button starts your debug log recording all over again. The batch must have executed its 2-3 items, between the time you reset it and the page re-render (Because of "Reset" click ) got comleted.

Moreover 50 MB is org-wide limit for debug log storage, if an org reaches that limit Salesforce deletes oldest logs to accomodate new ones.

https://help.salesforce.com/HTViewHelpDoc?id=code_add_users_debug_log.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=code_add_users_debug_log.htm&language=en_US)

For Batch Apex, the easiest way to monitor is keep your Developer Console open, and access debug log from there (Provided the batch was triggered by you), or keep hitting "Reset" button frequently on "Debug Logs" pages so that the added user doesnt go beyond 20 count and Salesforce never stop recording.