Context & Related Objects

Maximizing the value of your log data through rich context and related object tracking in Triton logging.

Maximizing Log Value

The most valuable logs contain rich context that enables effective debugging and analysis. Triton provides powerful capabilities for capturing comprehensive context and tracking related objects.

Apex – Single Object

Triton.instance.log(
    Triton.instance.fromTemplate()
        .relatedObject(accountId)  // Single related object
        .summary('Account processed')
        .details('status=completed')
);

Apex – Multiple Objects

// Order processing with related objects
public class OrderProcessingService {
    public static void processOrder(Id orderId) {
        // Set up template for order processing
        Triton.instance.setTemplate(
            Triton.makeBuilder()
                .category(TritonTypes.Category.Apex)
                .type(TritonTypes.Type.Backend)
                .area(TritonTypes.Area.OrderProcessing)
                .relatedObject(orderId)  // Primary object
        );
        
        try {
            // Get related records
            Order order = [SELECT Id, AccountId, OpportunityId FROM Order WHERE Id = :orderId];
            
            // Process order
            processOrderLogic(order);
            
            // Log success with all related objects
            Triton.instance.log(
                Triton.instance.fromTemplate()
                    .summary('Order processed successfully')
                    .details('orderId=' + orderId)
                    .relatedObjects(new Set<Id>{
                        orderId,           // Order
                        order.AccountId,   // Account
                        order.OpportunityId // Opportunity
                    })
            );
            
        } catch (Exception e) {
            Triton.instance.log(
                Triton.instance.fromTemplate()
                    .exception(e)
                    .summary('Order processing failed')
            );
            throw e;
        }
    }
}

Rich Context Capture

Duration Tracking

Integration Payloads

Context Enrichment

User Context

Runtime Information

Best Practices

  1. Primary object: Always include the main object being processed

  2. Related records: Include parent/child relationships that are relevant to the operation

  3. Transaction scope: Include all objects that are part of the same transaction

  4. Error context: Ensure related objects are included even in error scenarios

Context Enrichment

  1. Duration tracking: Measure and log processing time for performance analysis

  2. Integration payloads: Always include request/response data for external calls

  3. User context: Include user information for audit trails

  4. Runtime information: Capture relevant system/environment details

Performance Considerations

  1. Object limits: Be mindful of the number of related objects (avoid excessive lists)

  2. Payload size: Sanitize integration payloads to avoid storage issues

  3. Memory usage: Consider the impact of rich context on memory consumption

  4. Filtering: Use context to enable effective log filtering and analysis

Advanced Patterns

Context Templates

By maximizing context and related object tracking, you'll create logs that provide comprehensive debugging information and enable powerful analysis capabilities across your Salesforce org.

Last updated