Implementation Patterns
Real-world implementation patterns for Triton logging across different Salesforce contexts including triggers, batches, queueables, and flows.
Where to Insert Logs
General pattern:
Entry: Start/resume transaction, log intent (INFO).
Milestones: Key steps with metrics (INFO/DEBUG + duration, counts).
Decision points: Branches affecting outcome (DEBUG).
External calls: Before/after callouts (INFO, duration; attach sanitized request/response).
Errors/Recovery: Catch,
exception(...), add full context, immediately flush.Exit: Summarize result and timing, flush.
Triggers (Handler)
public with sharing class AccountTriggerHandler {
public static void beforeUpdate(List<Account> newList, Map<Id, Account> oldMap) {
Triton.instance.startTransaction();
Triton.instance.setTemplate(
Triton.makeBuilder()
.category(TritonTypes.Category.Apex)
.type(TritonTypes.Type.AccountTrigger)
.area(TritonTypes.Area.Accounts)
.createdTimestamp()
);
Set<Id> scopeIds = new Map<Id, Account>(newList).keySet();
Triton.instance.log(
Triton.instance.fromTemplate()
.level(TritonTypes.Level.INFO)
.summary('Account before update')
.details('count=' + scopeIds.size() + ', op=' + Trigger.operationType)
.relatedObjects(scopeIds)
);
}
}Queueable
Batchable
LWC β With @wire
@wireLWC β Imperative
Flow
Use the Triton invocable action (Add Log) to log milestones and errors from flows. This declarative approach integrates seamlessly with Flow Builder and provides comprehensive logging capabilities.
Key Flow Logging Strategies:
Strategic Placement: Add log actions at critical points:
Flow Start: Capture initiation and input parameters
User Interactions: Record form submissions and decisions
Data Operations: Log before/after DML operations and callouts
Decision Points: Document which logic branches are followed
Error Paths: Add detailed logging in fault connectors
Essential Parameters:
Interview GUID: Always use
$Flow.InterviewGuidfor proper log grouping and error correlationArea: Set to appropriate business domain (e.g.,
Accounts,Opportunities)Category: Typically
Flowfor most logging scenariosType: Specify flow type (e.g.,
Screen Flow,Autolaunched Flow)Summary: Brief description of the log entry
Details: Include record IDs, decision variables, and contextual data
Best Practices:
Use Constants: Create constants for common parameters (Area, Category, Type) to maintain consistency
Text Templates: Use text templates for log details to combine static text with dynamic flow data
Naming Conventions: Prefix resources with "Log_" for easy filtering
Additional Fields: Use JSON-formatted additional fields for extra contextual data when needed
Automatic Error Capture: Triton automatically captures unhandled Flow exceptions and correlates them with your custom logs using the Interview GUID, providing enhanced debugging information including stack traces, user context, and related object details.
Log Grouping: All logs from the same Flow instance are automatically grouped under a parent log using the Interview GUID, creating a complete execution trace for troubleshooting.
Integration Patterns
REST API Controllers
Scheduled Jobs
Best Practices Summary
Start transactions early: Begin at the entry point of each context
Set templates consistently: Use templates for all logging within a scope
Log at boundaries: Entry, milestones, decision points, errors, exit
Handle errors properly: Always log exceptions and flush immediately
Use appropriate levels: INFO for milestones, DEBUG for details, ERROR for failures
Include context: Related objects, duration, operation details
Stop transactions: Always end transactions at natural boundaries
By following these implementation patterns, you'll create comprehensive logging coverage across all your Salesforce automation and code.
Last updated