Triton
This articles covers all the logging methods, including those located in TritonLwc and TritonFlow classes.
Transaction Methods
These methods are responsible for establishing and maintaining a transaction context. A transaction is identified by either an auto-generated transaction Id or the standard request Id provided by Salesforce. These methods can be found in the main class Triton.cls.
startTransaction()
Start new transaction. This method will obtain a new auto-genrated transaction id.
Returns the current transaction Id.
resumeTransaction(String transactionId)
Resumes a transaction and assumes an existing transaction id. Use this method to tie together different Salesforce transactions into a larger transaction.
transactionId
-- An existing transaction Id
stopTransaction()
Stops a transaction and resets the current transaction Id. Use this method to marking tracking logs with the current transaction Id.
Apex Logging Methods
There are two types of log methods per each category: buffered and immediate. Buffered methods will add to the log collection without flush()-ing. Immediate methods will add to the log collection and call flush(). Buffered log methods are prefixed with add. The reference below covers only the buffered methods as their immediate counterparts have the same signatures. These methods can be found in the main class Triton.cls.
add(pharos__Log__c log)
Adds a log to the buffer. Performs a check on current log level prior.
log
-- Pharos log record
addError(Type type, Area area, String summary, String details)
Add Log with Error Category. This method will automatically get the stacktrace and save it on the log record.
The corresponding immediate method:
type
-- log record Type (see Type enum)
area
-- log record Functional Area (see Area enum)
summary
-- summary of the issue. Saves to log record Summary field
details
-- details of the issue. Saves to log record Details field
addError(Area area, Exception e)
Adds a Log with Error Category. This method will automatically get the stacktrace from the passed in Exception instance. Type will be obtained from Exception as well. If blank, a default Backend Type will be saved. Log Summary is the Exception message and Log Details will be a combination of the Exception string and stack trace.
The corresponding immediate method:
area
-- log record Functional Area (see Area enum)
e
--instance of an Exception
addWarning(Type type, Area area, String summary, String details)
Adds a Log with Warning category. This method will not save a stack trace.
The corresponding immediate method:
type
-- log record Type (see Type enum)
area
-- log record Functional Area (see Area enum)
summary
-- summary of the issue. Saves to log record Summary field
details
-- details of the issue. Saves to log record Details field
addDebug(Type type, Area area, String summary, String details)
Adds a Log with Debug category. This method will automatically get the stack trace.
The corresponding immediate method:
type
-- log record Type (see Type enum)
area
-- log record Functional Area (see Area enum)
summary
-- summary of the issue. Saves to log record Summary field
details
-- details of the issue. Saves to log record Details field
addDebug(Type type, Area area, String summary, String details)
Adds a Log with Debug category and saves the execution duration. This method will automatically get the stack trace.
The corresponding immediate method:
type
-- log record Type (see Type enum)
area
-- log record Functional Area (see Area enum)
summary
-- summary of the issue. Saves to log record Summary field
details
-- details of the issue. Saves to log record Details field
duration
-- a custom decimal value representing the duration of the execution (in milliseconds)
addEvent(Level level, Type type, Area area, String summary, String details)
Add a Log with Event category and a custom Log Level (see Level Enum).
The corresponding immediate method:
type
-- log record Type (see Type enum)
area
-- log record Functional Area (see Area enum)
summary
-- summary of the issue. Saves to log record Summary field
details
-- details of the issue. Saves to log record Details field
level
-- log level (see Level Enum)
addEvent(Type type, Area area, String summary, String details)
Add a Log with Event category and an INFO Log Level (see Level Enum).
The corresponding immediate method:
type
-- log record Type (see Type enum)
area
-- log record Functional Area (see Area enum)
summary
-- summary of the issue. Saves to log record Summary field
details
-- details of the issue. Saves to log record Details field
addIntegrationError(Area area, Exception e, HttpRequest request, HttpResponse response)
Add Log with Integration category that also saves http request and response payloads. This method will automatically get the stack trace from Exception.
The corresponding immediate method:
area
-- log record Functional Area (see Area enum)
e
-- instance of an Exception
request
-- an instance of HttpRequest. Saves to log record Details field
response
-- an instance of HttpResponse. Saves to log record Details field
addIntegrationError(Type type, Area area, String summary, String details, HttpRequest request, HttpResponse response)
Add Log with Integration category that also saves http request and response payloads. This method will automatically get the stack trace from Exception.
The corresponding immediate method:
type
-- log record Type (see Type enum)
area
-- log record Functional Area (see Area enum)
summary
-- a brief summary string
details
-- a detailed description string
request
-- an instance of HttpRequest. Saves to log record Details field
response
-- an instance of HttpResponse. Saves to log record Details field
addIntegrationError(Type type, Area area, String summary, String details, RestRequest request, RestResponse response)
Add Log with Integration category that also saves rest request and response payloads. This method will automatically get the stack trace from Exception.
The corresponding immediate method:
type
-- log record Type (see Type enum)
area
-- log record Functional Area (see Area enum)
summary
-- a brief summary string
details
-- a detailed description string
request
-- an instance of RestRequest. Saves to log record Details field
response
-- an instance of RestResponse. Saves to log record Details field
Here's the markdown documentation for the requested methods from Triton.cls:
addDMLResult(Area area, List<Object> dmlResults)
Add Log with Error Category for DML operation results. This method automatically captures failed operations and related record IDs from Database operation results (SaveResult, DeleteResult, etc.).
The corresponding immediate method:
area - log record Functional Area (see Area enum)
dmlResults - List of Database operation results (SaveResult, DeleteResult, UndeleteResult, UpsertResult, or MergeResult)
Supported DML Result Types:
Database.SaveResult
Database.DeleteResult
Database.UndeleteResult
Database.UpsertResult
Database.MergeResult
This method will create a log with the following additional attributes:
Category: Apex
Type: DMLResult
Level: ERROR (only logs failures)
Summary: Contains operation type and failure statistics
Details: Contains all error messages
Related Objects: Contains IDs of failed records
Example usage:
The above example will create an error log if any accounts fail to insert, including:
Which records failed (IDs in Related Objects)
How many records failed vs total
All error messages from the failed operations
All Purpose Logging
setTemplate(TritonBuilder builder)
Sets a builder template that can be reused for creating multiple log entries with similar base attributes.
builder
-- TritonBuilder instance to be used as a template
Example:
fromTemplate()
Retrieves a copy of the previously saved template builder. The returned builder includes the current transaction ID.
Returns:
TritonBuilder
-- A cloned instance of the template builder with the current transaction ID set
Example:
addLog
Adds a log entry to the buffer using a TritonBuilder instance. This method automatically captures the stack trace if one isn't already provided in the builder.
builder
- Configured TritonBuilder instance containing log entry details
Example:
log
Immediately persists a log entry to the database. This method combines addLog()
and flush()
operations into a single call.
builder
- Configured TritonBuilder instance containing log entry details
Example:
LWC Logging Methods
This methods is used by the LWC logger from custom LWC components. This method is located in TritonLwc.cls.
saveComponentLogs(List<ComponentLog> componentLogs)
Saves component logs from LWC. This method will publish immediately. Use this method to persist logs generated from LWC components.
Category will be fetched from the componentLog.
Type will be fetched from the componentLog directly, or from the error. If neither are set a default Frontend category will be used.
Area will be fetched from the componentLog directly if set. Otherwise component name will be used.
Summary will be fetched from the componentLog directly if set. Otherwise, error message will be used if provided.
Transaction Id will be used from the componentLog, or a new transaction id will be generated.
Apex Name (Operation) will be set to component.function or component.action.
Created Timestamp will be either set from the componentLog if provided, otherwise current timestamp will be used.
Log Level will be taken from the componentLog if provided, otherwise INFO will be used.
componentLogs
-- a collection of ComponentLog records (see ComponentLog class)
Flow Logging Methods
This method is used by Flows or Process Builder to generate logs. It is located in TritonFlow.cls.
log(List flowLogs)
Invocable method, that can be called via flow. Defaults to INFO log level (see Level Enum).
flowLogs
-- a collection of FlowLog records (see FlowLog class)
Last updated