# Best Practices & Standards

> **Audience:** Salesforce architects and senior developers\
> **Context:** Brand-new Triton rollout in an org with significant legacy automation & code

This comprehensive guide defines **authoritative, practical standards** for implementing the **Pharos Triton** logging framework across Apex, LWC, and Flow. It blends **Triton-specific** capabilities with **Salesforce engineering best practices**, focuses on **maximizing context and consistency**, and shows realistic code patterns for Batch, Queueable, Triggers, LWC, and Exception logging.

## What You'll Learn

This guide covers everything from fundamental logging principles to advanced implementation strategies:

* **Core Principles**: Understanding the foundational goals and principles of effective logging
* **Log Levels**: When and how to use different log levels appropriately
* **Template Patterns**: Leveraging templates for consistency and maintainability
* **Buffering & Flushing**: Smart strategies for performance and reliability
* **Transaction Management**: Correlating logs across LWC → Apex → Flow boundaries
* **Implementation Patterns**: Real-world examples for different Salesforce contexts
* **Context & Related Objects**: Maximizing the value of your log data
* **Taxonomy & Standards**: Establishing consistent classification systems
* **Exception Handling**: Best practices for error logging and debugging
* **Standards Enforcement**: Code review checklists and CI automation
* **Legacy Migration**: Strategies for rolling out Triton in existing orgs

## The Logging Challenge

Implementing a comprehensive logging framework in a Salesforce org presents unique challenges that go far beyond simply adding debug statements. Organizations often struggle with fragmented logging approaches, inconsistent patterns, and the inability to correlate issues across different technologies and contexts. When problems arise in production, teams find themselves piecing together information from multiple sources—debug logs, error emails, Flow execution details, and user reports—often without the context needed to quickly identify root causes.

The complexity increases exponentially when dealing with modern Salesforce architectures that span multiple technologies. A single user action might trigger an LWC component, which calls an Apex controller, which triggers a Flow, which executes additional Apex code, and potentially makes external API calls. When something goes wrong in this chain, traditional debugging approaches fall short. Teams spend hours or days trying to trace the execution path, often resorting to guesswork or extensive manual investigation. This not only impacts developer productivity but also directly affects business operations, customer experience, and support costs.

Moreover, the lack of standardized logging creates technical debt that compounds over time. Different developers implement logging in different ways, leading to inconsistent data quality, varying levels of detail, and difficulty in establishing meaningful patterns. Without proper structure and taxonomy, logs become noise rather than actionable intelligence. Organizations find themselves with terabytes of log data but little ability to extract meaningful insights or quickly resolve issues.

This guide addresses these fundamental challenges by providing a comprehensive framework that ensures consistency, enables correlation across technology boundaries, and delivers the rich context needed for effective debugging and monitoring. By following these best practices, organizations can transform their logging from a reactive debugging tool into a proactive observability platform that supports both immediate troubleshooting and long-term system optimization.

## Getting Started

We recommend working through these articles in order, as each builds upon the previous concepts:

| Article                                                                                                  | Description                                                                                                                                    |
| -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| [Core Principles](/pharos-triton/triton-best-practices/core-principles.md)                               | Understanding the foundational goals and principles of effective Triton logging implementation across Salesforce technologies.                 |
| [Log Levels: When to Use What](/pharos-triton/triton-best-practices/log-levels-and-usage.md)             | Understanding when and how to use different log levels appropriately in Triton logging for optimal debugging and monitoring.                   |
| [Templates & the Builder Pattern](/pharos-triton/triton-best-practices/templates-and-builder-pattern.md) | Leveraging templates and the builder pattern for consistent, maintainable Triton logging across Apex and LWC.                                  |
| [Buffering & Flushing](/pharos-triton/triton-best-practices/buffering-and-flushing.md)                   | Smart strategies for buffering and flushing logs in Triton for optimal performance and reliability across Apex and LWC.                        |
| [Transaction Management](/pharos-triton/triton-best-practices/transaction-management.md)                 | Correlating logs across LWC → Apex → Flow boundaries using transaction management for end-to-end traceability.                                 |
| [Implementation Patterns](/pharos-triton/triton-best-practices/implementation-patterns.md)               | Real-world implementation patterns for Triton logging across different Salesforce contexts including triggers, batches, queueables, and flows. |
| [Context & Related Objects](/pharos-triton/triton-best-practices/context-and-related-objects.md)         | Maximizing the value of your log data through rich context and related object tracking in Triton logging.                                      |
| [Taxonomy & Standards](/pharos-triton/triton-best-practices/taxonomy-and-standards.md)                   | Establishing consistent classification systems and taxonomy standards for Triton logging across your Salesforce org.                           |
| [Exception Handling](/pharos-triton/triton-best-practices/exception-handling.md)                         | Best practices for error logging and debugging with Triton, including exception handling patterns and debugging strategies.                    |
| [Standards Enforcement](/pharos-triton/triton-best-practices/standards-enforcement.md)                   | Code review checklists and CI automation for enforcing Triton logging standards across your Salesforce org.                                    |
| [Legacy Code Logging Rollout](/pharos-triton/triton-best-practices/legacy-migration.md)                  | Strategies for rolling out Triton logging in existing Salesforce orgs with legacy automation and code.                                         |

## Key Benefits

By following these best practices, your org will achieve:

* **Consistent Logging**: Standardized patterns across all code and automation
* **Rich Context**: Comprehensive debugging information with minimal effort
* **Performance Optimization**: Smart buffering and flushing strategies
* **End-to-End Tracing**: Complete visibility across technology boundaries
* **Maintainable Code**: Template-based approaches that reduce duplication
* **Production Readiness**: Proper error handling and monitoring capabilities


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://triton.pharos.ai/pharos-triton/triton-best-practices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
