Pharos Triton
  • 🔱About Pharos Triton
  • 🏁Installing Pharos Triton
  • Apex Logging Basics
  • Common Apex Usage Patters
    • Batch Logging
    • Integration Logs
    • Apex Rest Logging
    • Full Control with TritonBuilder
  • Beyond Apex
    • LWC
    • 🔄LWC Transaction Management
    • ⚡LWC and Apex
    • 💾Platform Cache for Transactions
    • Flows
    • 〰️LWC, Apex and Flows
  • 📖Methods Reference
    • 📔Apex
      • Triton
      • TritonBuilder
      • TritonTypes
      • TritonLwc
        • ComponentLog
        • Component
        • Error
        • RuntimeInfo
      • TritonFlow
        • FlowLog
      • TritonHelper
        • PostProcessingControlsBuilder
      • LogBuilder
    • LWC
      • Triton
      • TritonBuilder
      • TritonUtils
  • Help and Support
Powered by GitBook
On this page
  • Core Instance
  • instance
  • Transaction Methods
  • startTransaction()
  • resumeTransaction(String transactionId)
  • stopTransaction()
  • Apex Logging Methods
  • add(pharos__Log__c log)
  • addError(Type type, Area area, String summary, String details)
  • addError(Area area, Exception e)
  • addWarning(Type type, Area area, String summary, String details)
  • addDebug(Type type, Area area, String summary, String details)
  • addDebug(Type type, Area area, String summary, String details)
  • addEvent(Level level, Type type, Area area, String summary, String details)
  • addEvent(Type type, Area area, String summary, String details)
  • addIntegrationError(Area area, Exception e, HttpRequest request, HttpResponse response)
  • addIntegrationError(Type type, Area area, String summary, String details, HttpRequest request, HttpResponse response)
  • addIntegrationError(Type type, Area area, String summary, String details, RestRequest request, RestResponse response)
  • addDMLResult(Area area, List<Object> dmlResults)
  • All Purpose Logging
  • setTemplate(TritonBuilder builder)
  • fromTemplate()
  • addLog
  • log
  • LWC Logging Methods
  • saveComponentLogs(List<ComponentLog> componentLogs)
  • Flow Logging Methods
  • log(List flowLogs)
  1. Methods Reference
  2. Apex

Triton

This article covers all the logging methods, including transaction management and DML result logging.

Core Instance

instance

public static Triton instance { get; private set; }

Singleton instance of the Triton logger. All logging operations should be performed through this instance.

Example:

Triton.instance.addError(TritonTypes.Area.Accounts, e);

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()

public String startTransaction()

Starts a new transaction with an auto-generated transaction ID.

Returns:

  • Current transaction ID

resumeTransaction(String transactionId)

public void resumeTransaction(String transactionId)

Resumes an existing transaction. Use this to tie together different Salesforce transactions.

Parameters:

  • transactionId - Existing transaction ID to resume

stopTransaction()

public void stopTransaction()

Stops the current transaction and resets the 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)

public void 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.

public void addError(Type type, Area area, String summary, String details)

The corresponding immediate method:

public void error(Type type, Area area, String summary, String details)

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.

public void addError(Area area, Exception e)

The corresponding immediate method:

public void error(Area area, Exception e)

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.

public void addWarning(Type type, Area area, String summary, String details)

The corresponding immediate method:

public void warning(Type type, Area area, String summary, String details)

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.

public void addDebug(Type type, Area area, String summary, String details)

The corresponding immediate method:

public void debug(Type type, Area area, String summary, String details)

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.

public void addDebug(Type type, Area area, String summary, String details, Decimal duration)

The corresponding immediate method:

public void debug(Type type, Area area, String summary, String details, Decimal duration)

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)

public void addEvent(Level level, Type type, Area area, String summary, String details)

The corresponding immediate method:

public void event(Level level, Type type, Area area, String summary, String details)

summary -- summary of the issue. Saves to log record Summary field

details -- details of the issue. Saves to log record Details field

addEvent(Type type, Area area, String summary, String details)

public void addEvent(Type type, Area area, String summary, String details)

The corresponding immediate method:

public void event(Type type, Area area, String summary, String details)

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.

public void addIntegrationError(Area area, Exception e, HttpRequest request, HttpResponse response)

The corresponding immediate method:

public void integrationError(Area area, Exception e, HttpRequest request, HttpResponse response)

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.

public void addIntegrationError(Type type, 
                                Area area, 
                                String summary, 
                                String details, 
                                HttpRequest request, 
                                HttpResponse response)

The corresponding immediate method:

public void integrationError(Type type, 
                                Area area, 
                                String summary, 
                                String details, 
                                HttpRequest request, 
                                HttpResponse response)

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.

public void addIntegrationError(Type type, 
                                Area area, 
                                String summary, 
                                String details, 
                                RestRequest request, 
                                HttpResponse response)

The corresponding immediate method:

public void integrationError(Type type, 
                                Area area, 
                                String summary, 
                                String details, 
                                RestRequest request, 
                                RestResponse response)

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.).

public void addDMLResult(Area area, List<Object> dmlResults)

The corresponding immediate method:

public void dmlResult(Area area, List<Object> dmlResults)
  • 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:

List<Account> accounts = new List<Account>();
// ... populate accounts ...
List<Database.SaveResult> results = Database.insert(accounts, false);
Triton.instance.addDMLResult(TritonTypes.Area.AccountManagement, results);

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)

public void 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:

TritonBuilder template = Triton.makeBuilder()
    .category(TritonTypes.Category.Apex)
    .area(TritonTypes.Area.OpportunityManagement)
    .level(TritonTypes.Level.INFO);
Triton.instance.setTemplate(template);

fromTemplate()

public TritonBuilder 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:

TritonBuilder builder = Triton.instance.fromTemplate()
    .summary('New log entry')
    .details('Log details');

addLog

public void addLog(TritonBuilder builder)

Adds a log entry to the buffer using a TritonBuilder instance. Automatically captures stack trace if not provided.

Parameters:

  • builder - Configured TritonBuilder instance

Example:

Triton.instance.addLog(
    Triton.makeBuilder()
        .category(TritonTypes.Category.Apex)
        .type(TritonTypes.Type.Backend)
        .area(TritonTypes.Area.OpportunityManagement)
        .summary('Process completed')
        .details('Operation successful')
);

log

public void log(TritonBuilder builder)

Immediately persists a log entry. Combines addLog() and flush() operations.

Parameters:

  • builder - Configured TritonBuilder instance

Example:

Triton.instance.log(
    Triton.makeBuilder()
        .category(TritonTypes.Category.Apex)
        .type(TritonTypes.Type.Backend)
        .area(TritonTypes.Area.OpportunityManagement)
        .summary('Critical operation completed')
        .details('Operation successful')
        .level(TritonTypes.Level.INFO)
);

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.

@AuraEnabled
public static void saveComponentLogs(List<ComponentLog> componentLogs)

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)

@InvocableMethod(Category='Logging' 
                Label='Add Log' 
                Description='Creates logs from flow or process builder')
public static void log(List<FlowLog> flowLogs)

flowLogs -- a collection of FlowLog records (see FlowLog class)

PreviousApexNextTritonBuilder

Last updated 2 months ago

type -- log record Type (see )

area -- log record Functional Area (see )

area -- log record Functional Area (see )

type -- log record Type (see )

area -- log record Functional Area (see )

type -- log record Type (see )

area -- log record Functional Area (see )

type -- log record Type (see )

area -- log record Functional Area (see )

Add a Log with Event category and a custom Log Level (see ).

type -- log record Type (see )

area -- log record Functional Area (see )

level -- log level (see )

Add a Log with Event category and an INFO Log Level (see ).

type -- log record Type (see )

area -- log record Functional Area (see )

area -- log record Functional Area (see )

type -- log record Type (see )

area -- log record Functional Area (see )

type -- log record Type (see )

area -- log record Functional Area (see )

Invocable method, that can be called via flow. Defaults to INFO log level (see ).

📖
📔
Type enum
Area enum
Area enum
Type enum
Area enum
Type enum
Area enum
Type enum
Area enum
Level Enum
Type enum
Area enum
Level Enum
Level Enum
Type enum
Area enum
Area enum
Type enum
Area enum
Type enum
Area enum
Level Enum