Customers using the Fen-X package in Salesforce (SF) may wish to delete older log entries to free up storage space. While this is possible by manually bulk-deleting SF logs, this process is time consuming. A more suitable way of purging logs is to use automated log deletion classes. This brief KBA outlines the available log purging classes, and the process through which a customer can activate them.
The relevant classes are “LogBatchPurger” and “LogBatchPurgeScheduler”. Customers can use these to automate the log deletion process. To access this functionality, the classes must be set to “Active” within SF. See the below image.
If we want to set up a job to automatically remove the logs from salesforce which are created by Fenx app, please follow following steps:
Scheduling Job
· This job will run daily and delete the logs to free up the space in the Salesforce.
· Goto Setup > Search for Scheduled Jobs
o Click on Scheduled Apex
o Job Name (Log Batch Purger)
o Apex Class (search for this class: LogBatchPurgeScheduler)
o Schedule Using (Schedule Builder)
o Schedule Apex Execution
Frequency (Weekly) check the checkboxes for all the days
Start (current date)
End (31/12/2099 / according to your need)
Preferred Start Time (01:00)
Click on Save
Furthermore, within the Logger Settings, the “Default Number of Days to Retain Logs” can be configured so that logs are automatically removed after x number of days. If this value is left blank (null), logs will be kept indefinitely. See the below example, where the default has been set to 14 days.
Go to Setup > Search for Custom Settings. Click on Logger Settings > Click on Manage > Edit Change Default Number of Days to Retain Logs
Customers have access to both classes mentioned above - they can kick off and automate them as they wish. The standard SF System.schedule can be used to run the code as desired. For example:
String sch = '0 0 12 ? * SUN *'; // this is up to the clients' decision, this is an example - this will run job only Sunday every week. System.schedule('Schedule of LogBatchPurgeScheduler', sch, new Fenx.LogBatchPurgeScheduler());
It is up to the customer to decide how to run the code. For example, they could run it in the SF Anonymous Apex Code window. The SF admins on the customer’s side should be familiar with the class enabling process within SF.