CPQ Logger
Available in: Enxoo Commerce |
CPQ Logger allows us to programmatically create log entries, which are saved in the CPQ Log object. It is designed as a unified place to capture code errors, custom event logs, and other things that have to be monitored during the application lifecycle.
Viewing Logs
CPQ Logs are saved as records in the CPQ Log custom object (enxCPQ__CPQ_Log).
CPQ Logs are custom functionality that is not related to Salesforce Debug Logs.
Setting Debug Level
To enable logging, set Debug Level using CPQ Settings (Enxoo Settings).
CPQ_LOGGING_LEVEL setting is available in the Global Setting tab. Following levels are available:
NONE (default) - no logs will be saved
ERROR - error logs will be saved
INFO - error & info logs will be saved
ALL - all logs will be saved
Creating Logs Programatically
Step by step guide
Logs creation is handled by utility class enxCPQ.CPQ_Utils15_Logger
Step 1. At the beginning of transaction get the instance of CPQ Logger calling getLogger() method:
enxCPQ.CPQ_Utils15_Logger logger = enxCPQ.CPQ_Utils15_Logger.getLogger();
Step 2. In order to create a new log call logger.createLog() method.
logger.createLog(new enxCPQ.CPQ_Utils15_Logger.LogItem()
.setLevel(enxCPQ.CPQ_Utils.LOG_LEVEL_INFO)
.setType(enxCPQ.CPQ_Utils.LOG_TYPE_PLATFORMEVENT)
.setSubtype(event.enxCPQ__Event_Type__c)
.setSource(event.enxCPQ__Source_Id__c)
.setMessage(String.valueOf(event)));
In order for the log to be created, you need to set required log fields: Level, Type, Subtype
Step 3. In order to save logs, call logger.commitLogs() method.
logger.commitLogs();
Field References
Field | Field Type | Comments | Field Value | Apex String |
---|---|---|---|---|
Level | Picklist | Required | Error | enxCPQ.LOG_LEVEL_ERROR |
Info | enxCPQ.LOG_LEVEL_INFO | |||
All | enxCPQ.LOG_LEVEL_ALL | |||
Type | Picklist | Required | Apex | LOG_TYPE_APEX |
Webservice | LOG_TYPE_WEBSERVICE | |||
Platform Event | LOG_TYPE_PLATFORMEVENT | |||
Custom | LOG_TYPE_CUSTOM | |||
Other | LOG_TYPE_OTHER | |||
Subtype | Text (255) | Required | ||
Source | Text (255) | Optional | ||
Message | Long Text (5000) | Optional |
Code Example
Please find this example as a reference:
trigger B2B_EVT_AllTriggers on enxCPQ__CPQ_Event__e (after insert) {
enxCPQ.CPQ_Utils15_Logger logger = enxCPQ.CPQ_Utils15_Logger.getLogger();
for (enxCPQ__CPQ_Event__e event : Trigger.new) {
logger.createLog(new enxCPQ.CPQ_Utils15_Logger.LogItem()
.setLevel(enxCPQ.CPQ_Utils.LOG_LEVEL_INFO)
.setType(enxCPQ.CPQ_Utils.LOG_TYPE_PLATFORMEVENT)
.setSubtype(event.enxCPQ__Event_Type__c)
.setSource(event.enxCPQ__Source_Id__c)
.setMessage(String.valueOf(event)));
if (...) {
// ... some logic ...
}
}
try {
OrderStatusAuto statAut = new OrderStatusAuto(techIds);
statAut.updateOrderItemsStatus();
} catch (Exception ex) {
logger.createLog(new enxCPQ.CPQ_Utils15_Logger.LogItem()
.setLevel(enxCPQ.CPQ_Utils.LOG_LEVEL_ERROR)
.setType(enxCPQ.CPQ_Utils.LOG_TYPE_PLATFORMEVENT)
.setSubtype('ORDER_STATUS_AUTOMATION')
.setSource('ORDER TECH IDS: ' + techIds)
.setMessage(ex.getMessage()));
}
logger.commitLogs();
}
Table of Contents