Handling multiple records in bulk is an integral part of the development using Salesforce platform. Salesforce provides extensive logging capability for the developer to log the events on a transaction, but when processing multiple records in a transaction or when processing the record data across multiple transactions, it becomes very challenging to check a flow happened on a record.
With Record Logger App, we are providing a framework for the developers to log on the record. This framework can be used to provide visibility of the functional logic path the system enforces on the record to users. This app can be handy in Field debugging.
Record Logger application provides a framework for developers to log in Apex code. It helps the admin and business users to check whether the system is working as expected with a click of a button. This document will go through the features of this application, and the steps admin must follow to bring the most out of the application.
Record Logger application revolves around following concepts.
- Log Transactio
Log Transaction object represents a transaction in execution. For every transaction that involves log will have one Log Transaction record.
Log object will hold the log for the record. Internally one Log record for the Salesforce record holds multiple Log messages.
Record Logger is a managed application hosted in the Salesforce app exchange.
Logging is a common functionality. As any users can execute the Apex code containing log statements, during installation, when prompted select [Install for All Users].
After installation, the following configurations need to be performed by the Admin to customize the application for their needs.
Log setting is the custom metadata where Admin can configure the message count threshold and retention hours in custom setting record named [Global].
Message Count Threshold
Message count threshold is the maximum number of log messages should be held in memory in a transaction, before writing to Database.
Retention Hours is the period how long the log records have to reside in the system. Default: 48 hours
Enabled Tags is comma separated values of tags. Developers can use tags to differentiate various flows log messages.
By giving different tags in enabled tags field as a comma separated values, the system will store only the log messages with that tags in the internal object. It will ignore the logs with other tags.
By specifying no enabled tags, the system will store all the log messages for all tags in the internal object.
From setup, click on custom metadata. In the list, identify [Log Setting]. Click on Manage Records in Log Setting.
Edit the record with the name [Global], if you want to change either retention hours and message count threshold or both.
Upon installation, Users on both Classic experience and Lightning experience will get Logger app and Log Viewer tab to view the logs for the record.
Show Log Button In Classic Experience
The application managed package contains necessary Visualforce pages, components and Lightning components to build buttons for record detail page to view the logs for the record.
Create custom button on the object whose log records should display with a click of a button.
The content source for the button should be [URL].
Replace ObjectAPIName in the below text in the custom button or link editor.
Place the button on the record page layout.
Log Viewer Action in Lightning Experience
Create a new action on the object with action type [Lightning component]. Choose [SharLog:RecordLogViewer] for the Lightning component.
Log CleanUp Job
Upon installation, System automatically schedules clean up job to delete log records older than retention period. Admin can customize scheduled job based on their needs. By default, a job for clean up will run every 6 hours.
To customize it, go to [Scheduled Jobs] from the setup, delete the job submitted by [SharLog].
From setup, go to apex class.
Click on [Schedule Apex] button.
Enter a job name and choose [LogCleanupScheduler] using lookup icon provided for apex class.
Choose a preferred time and start and end date.
Click on [Save].