# TritonHelper

This class is mostly for internal use and includes functionality for log level management, UUID generation, HTTP request/response serialization, and message formatting.

### Transaction Cache Methods

#### cacheTransactionId

```apex
public static void cacheTransactionId(String transactionId)
```

Saves transaction ID to platform cache with user-specific key. Silently handles cache failures.

**Parameters:**

* `transactionId` - Transaction ID to cache

#### getCachedTransactionId

```apex
public static String getCachedTransactionId()
```

Retrieves transaction ID from platform cache using user-specific key.

**Returns:**

* Cached transaction ID or null if not found

#### clearCachedTransactionId

```apex
public static void clearCachedTransactionId()
```

Clears transaction ID from platform cache.

### Stack Trace Methods

#### getCurrentStackTrace

```apex
public static String getCurrentStackTrace()
```

Returns the current stack trace as a string, excluding any Triton-related entries.

**Returns:**

* Filtered stack trace with lines joined by newline characters

#### getOperation

```apex
public static String getOperation(String stackTrace)
```

Extracts the operation (Class.Method) from a stack trace string, taking the topmost non-Triton entry.

**Parameters:**

* `stackTrace` - The stack trace string to parse

**Returns:**

* String in format "ClassName.MethodName"

### Runtime Info Formatting

#### formatLwcRuntimeInfo

```apex
public static String formatLwcRuntimeInfo(TritonLwc.RuntimeInfo runtime)
```

Formats runtime information from LWC into a readable string, including environment, performance, memory, network, and device details.

**Parameters:**

* `runtime` - The runtime info object to format

**Returns:**

* Formatted string with all runtime details

### Utility Methods

#### buildLogLevelKey

```apex
public static String buildLogLevelKey(String category, String type, String area)
```

Creates a key for log level based on category, type, and area parameters.

**Parameters:**

* `category` - Log category field
* `type` - Log type field
* `area` - Log functional area field

**Returns:**

* String in the format: `Category:{0};Type:{1};Area:{2}`

#### compareLevel

```apex
public static Boolean compareLevel(TritonTypes.Level value, TritonTypes.Level toCompare)
```

Compares two log levels to determine if logging should proceed.

**Parameters:**

* `value` - The level to compare against (from settings)
* `toCompare` - The level being compared (from log)

**Returns:**

* `true` if value is greater than or equal to toCompare
* `false` if value is lower than toCompare

#### generateUUID4

```apex
public static String generateUUID4()
```

Generates a UUID (Universal Unique Identifier) version 4. Used to create transaction IDs.

**Returns:**

* String containing a UUID4 formatted identifier

#### toJson (HTTP)

```apex
public static String toJson(HttpRequest request, HttpResponse response)
```

Serializes HTTP request and response objects to JSON format for integration logging.

**Parameters:**

* `request` - HttpRequest instance
* `response` - HttpResponse instance

**Returns:**

* JSON string containing formatted request and response data

#### toJson (REST)

```apex
public static String toJson(RestRequest request, RestResponse response)
```

Serializes REST request and response objects to JSON format for integration logging.

**Parameters:**

* `request` - RestRequest instance
* `response` - RestResponse instance

**Returns:**

* JSON string containing formatted request and response data

#### formatMessage (Single Parameter)

```apex
public static String formatMessage(String template, String param)
```

Formats a message by replacing {0} placeholder with the provided parameter.

**Parameters:**

* `template` - Message template containing {0} placeholder
* `param` - Parameter to replace the placeholder

**Returns:**

* Formatted message string

#### formatMessage (Multiple Parameters)

```apex
public static String formatMessage(String template, List<String> params)
```

Formats a message by replacing {0}, {1}, etc. placeholders with the provided parameters.

**Parameters:**

* `template` - Message template containing numbered placeholders
* `params` - List of parameters to replace the placeholders

**Returns:**

* Formatted message string

### Builder Class

#### PostProcessingControlsBuilder

Builder class for constructing Pharos post-processing settings. Controls various aspects of log enhancement after creation. You can find a more [detailed method reference here](/pharos-triton/methods-reference/apex-methods-reference/tritonhelper/postprocessingcontrolsbuilder.md).

**Methods**

```apex
public PostProcessingControlsBuilder auditTrail(Boolean value)
public PostProcessingControlsBuilder deployResult(Boolean value)
public PostProcessingControlsBuilder installedPackages(Boolean value)
public PostProcessingControlsBuilder area(Boolean value)
public PostProcessingControlsBuilder pendingJobs(Boolean value)
public PostProcessingControlsBuilder relatedObjects(Boolean value)
public PostProcessingControlsBuilder stackTrace(Boolean value)
public PostProcessingControlsBuilder userInfo(Boolean value)
public PostProcessingControlsBuilder totalActiveSession(Boolean value)
public PostProcessingControlsBuilder setAll(Boolean value)
```

Each method controls a specific aspect of post-processing:

* `auditTrail` - Controls fetching of recent audit trail
* `deployResult` - Controls fetching of recent deployments
* `installedPackages` - Controls fetching of installed package count
* `area` - Controls automatic functional area setting
* `pendingJobs` - Controls fetching of pending jobs in flow queue
* `relatedObjects` - Controls fetching of related object names
* `stackTrace` - Controls stack trace enhancement (Apex/Integration logs only)
* `userInfo` - Controls fetching of User name
* `totalActiveSession` - Controls fetching of current logged-in user count
* `setAll` - Sets all flags to the provided value

**Build Method:**

```apex
public String build()
```

Returns a JSON string representation of the post-processing controls.

**Example:**

```apex
String controls = new TritonHelper.PostProcessingControlsBuilder()
    .stackTrace(true)
    .userInfo(true)
    .relatedObjects(true)
    .build();
```

#### IntegrationWrapper

Wrapper class for integration logs used to create the JSON structure that combines HTTP objects.

**Properties:**

* `request` - Map\<String, Object> containing request details
* `response` - Map\<String, Object> containing response details

This class is primarily used internally by the toJson methods to structure integration log data.

### Runtime Information Components

#### [`RuntimeInfo` (in TritonLwc)](https://github.com/Pharos-AI/triton-docs/blob/main/apex-methods-reference/tritonhelper/tritonlwc.md#runtimeinfo)

Captures detailed runtime information from Lightning Web Components:

* Environment details (user agent, platform, language)
* Performance metrics (page load time, DOM events, paint times)
* Memory usage statistics
* Network information (connection type, speed, RTT)
* Device characteristics (form factor, screen dimensions)
* Navigation context (pathname, hostname)


---

# 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/methods-reference/apex-methods-reference/tritonhelper.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.
