> For the complete documentation index, see [llms.txt](https://triton.pharos.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonflow.md).

# TritonFlow

Documentation for the TritonFlow Apex class that provides core logging functionality for Flow Builder and Process Builder.

## Overview

The TritonFlow class provides the server-side implementation for Flow and Process Builder logging. It handles automatic transaction management, Flow context capture, and validation of logging parameters.

## Flow Logging Methods

### log

{% code lineNumbers="true" %}

```apex
@InvocableMethod(Category='TritonLogging' 
                Label='Log' 
                Description='Creates a log for a flow or process builder')
public static List<FlowLogOutput> log(List<FlowLog> flowLogs)
```

{% endcode %}

Creates logs from Flow or Process Builder. This method will:

* Create logs with default INFO level if not specified
* Handle automatic transaction management (create new or resume existing)
* Capture Flow context (Interview GUID, Flow API Name)
* Process custom field mapping through JSON
* Validate category and log level enums
* Return stacktrace information for error handling

**Returns:**

* List containing stacktrace information for each log

## Field Mapping Reference

### Core Fields

| Builder Method | Flow Source       | Required | Default                                                                   |
| -------------- | ----------------- | -------- | ------------------------------------------------------------------------- |
| `category()`   | flowLog.category  | No       | Flow [(see Categories)](https://triton.pharos.ai/core-concepts/enums.md)  |
| `type()`       | flowLog.type      | No       | - [(see Types)](https://triton.pharos.ai/core-concepts/enums.md)          |
| `area()`       | flowLog.area      | Yes      | - [(see Areas)](https://triton.pharos.ai/core-concepts/enums.md)          |
| `level()`      | flowLog.level     | No       | INFO [(see Levels)](https://triton.pharos.ai/core-concepts/log-levels.md) |
| `summary()`    | flowLog.summary   | Yes      | -                                                                         |
| `details()`    | flowLog.details   | No       | -                                                                         |
| `operation()`  | flowLog.operation | No       | -                                                                         |

For complete builder method documentation, see [TritonBuilder Reference](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonbuilder.md).

### Context Fields

> 🔍 **Flow Context**\
> The system automatically captures and sets critical Flow execution context:
>
> * Interview GUID for tracking specific Flow runs
> * Flow API Name for identifying the Flow definition
> * Transaction ID for cross-context correlation

{% code lineNumbers="true" %}

```json
{
  "interviewGuid": "required - from flowLog.interviewGUID",
  "flowApiName": "optional - from flowLog.flowApiName",
  "flowVersion": "optional - from flowLog.flowVersion",
  "transactionId": "auto-generated if not exists"
}
```

{% endcode %}

### Additional Fields

Custom fields can be passed through the `additionalFields` JSON string:

{% code lineNumbers="true" %}

```json
{
  "customField1": "value1",
  "customField2": "value2"
}
```

{% endcode %}

## Automatic Behaviors

> ⚡ **Smart Defaults**\
> The system provides intelligent default behaviors to ensure robust logging:

1. **Transaction Management**
   * Creates new transaction if none exists
   * Maintains transaction context across Flow elements
2. **Issue Creation**
   * Automatically creates issues for ERROR level logs
3. **Post-processing**
   * At every level, requests six post-processing controls: stack trace, user info, related objects, installed packages, pending jobs, and total active sessions
4. **Deferred Publishing**
   * Buffers logs and hands them off with [`Triton.drain()`](https://triton.pharos.ai/methods-reference/apex-methods-reference/triton.md#drain)
   * Publishes them on a short delay via [`TritonFlowFlushBatch`](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonflowflushbatch.md) to minimize platform event consumption
   * With **Disable Flow Flush Batch** set, publishes them in the Flow's own transaction instead
5. **Never Fails the Flow**
   * A log that can't be built is dropped without costing the others. If the publish fails, that publish's logs are dropped. Either way the failure is noted in the Apex debug log.
   * Always returns one output per input, so the Flow's output mapping holds

## Validation Rules

### Required Fields

* `area` - Functional area identifier
* `summary` - Log message summary
* `interviewGUID` - Flow interview identifier

### Enum Validation

The system validates and provides fallbacks for:

| Field     | Invalid Value Behavior        |
| --------- | ----------------------------- |
| Log Level | Defaults to INFO with warning |
| Category  | Defaults to Flow with warning |

### Error Handling

📝 **Validation Messages**\
When validation issues occur, the system:

1. Applies appropriate defaults
2. Appends warning messages to the details field
3. Continues processing without interruption

## Related Classes

The TritonFlow class works with:

* [FlowLog](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonflow/flowlog.md) - Main wrapper for Flow log data (and the `FlowLogOutput` return wrapper)
* [TritonFlowFlushBatch](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonflowflushbatch.md) - Deferred publishing of Flow logs
* [TritonBuilder](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonbuilder.md) - Core log building functionality
* [TritonTypes](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritontypes.md) - Enums and constants

### Transaction Management

The system provides two modes of transaction handling:

1. **Auto-Create**: If no transaction exists and no ID is provided, creates new
2. **Resume**: If transaction ID is provided, resumes existing transaction

This enables correlation of logs across different Flow elements and contexts.

### Stacktrace Handling

This functionality is facilitated by the X-Ray machine only. If logging manually, disregard these values.

1. **Current Trace**: Captured in `stacktrace` field
2. **Full Trace**: Combines previous traces with current in `fullStacktrace`
3. **Automatic Chaining**: Each FlowLogOutput contains the combined trace

This is used by the X-Ray machine for tracking error propagation through multiple Flow elements.
