> 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/tritonlwc.md).

# TritonLwc

Documentation for the TritonLwc Apex class that provides core logging functionality for Lightning Web Components.

## Overview

The TritonLwc class provides the server-side implementation for Lightning Web Component logging. It handles the reception and processing of client-side logs, managing transaction context, and ensuring proper log persistence.

## LWC Logging Methods

### saveComponentLogs

{% code lineNumbers="true" %}

```apex
@AuraEnabled
public static void saveComponentLogs(List<ComponentLog> componentLogs)
```

{% endcode %}

Creates logs from LWC components with automatic transaction management and context capture.

## Field Mapping Reference

### Core Fields

| Builder Method | Component Source                   | Default  | Description                                                                                              |
| -------------- | ---------------------------------- | -------- | -------------------------------------------------------------------------------------------------------- |
| `category()`   | componentLog.category              | LWC      | Component classification                                                                                 |
| `type()`       | componentLog.type/error.type       | Frontend | Technical classification                                                                                 |
| `area()`       | componentLog.area                  | LWC      | Functional area — any non-blank value is kept; a known area is normalized to its `TritonTypes.Area` name |
| `level()`      | componentLog.level                 | INFO     | Log severity                                                                                             |
| `summary()`    | componentLog.summary/error.message | -        | Main log message                                                                                         |
| `details()`    | componentLog.details + validation  | -        | Extended information                                                                                     |
| `stackTrace()` | componentLog.stack                 | -        | Error stack trace                                                                                        |

### Context Fields

> 🔍 **Component Context**\
> The system automatically captures rich component execution context:

{% code lineNumbers="true" %}

```json
{
  "operation": "componentName.functionName",
  "transactionId": "auto-generated or from component",
  "userId": "current user or specified",
  "createdTimestamp": "component time or server time",
  "duration": "execution time if provided",
  "action": "performance mark / backend call / interaction name",
  "spanId": "span identifier from the component",
  "parentSpanId": "parent span identifier from the component"
}
```

{% endcode %}

Span IDs (`spanId` / `parentSpanId`) let the LWC layer stitch client-side operations into a trace hierarchy that carries through to Apex. Limit info is not captured for component logs.

### Related Objects

> 🔗 **Record Context**\
> The system supports linking logs to Salesforce records:

{% code lineNumbers="true" %}

```json
{
  "relatedObjects": ["recordId1", "recordId2"],
  "validationRules": "15 or 18 character IDs",
  "behavior": "Invalid IDs are filtered"
}
```

{% endcode %}

## Automatic Behaviors

> ⚡ **Smart Processing**\
> The system provides intelligent handling of log data:

1. **Transaction Management**
   * Resumes the transaction id cached for the user (within the Cache TTL) when there is one; otherwise adopts the id the component sent, or starts a new one
   * Maintains transaction context across components
   * Correlates related logs
2. **Context Enrichment**
   * Captures component hierarchy
   * Records runtime metrics
   * Preserves error context
3. **Data Validation**
   * Validates all incoming fields
   * Provides sensible defaults
   * Maintains data integrity

## Validation Rules

### Required Field Validation

| Field    | Validation Rule                                                                                                        | Default Behavior                                                         |
| -------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| Category | Must be a `TritonTypes.Category` value                                                                                 | Falls back to `LWC`, with a note in Details                              |
| Type     | Any string                                                                                                             | Blank uses the error's type, then `Frontend`                             |
| Area     | Any string; a known area in any spelling (`'LEAD_CONVERSION'`, `'leadconversion'`) maps to its `TritonTypes.Area` name | Blank lands as `LWC`, with no note                                       |
| Level    | Must be a `TritonTypes.Level` value                                                                                    | Blank uses `INFO` with no note; an invalid value uses `INFO` with a note |

The silent blank-level default applies to LWC logs only: the Flow **Log** action still appends `Unable to locate log level: null` to Details for a blank level. An `ERROR` log from a component opens a Pharos issue.

### ID Validation

📝 **Record ID Processing**\
The system validates record IDs by:

1. Checking ID format (15 or 18 chars)
2. Filtering invalid IDs
3. Maintaining valid relationships

### Error Handling

> 🛡️ **Validation Strategy**\
> When validation issues occur:

* Invalid values get appropriate defaults
* Validation messages are added to details
* Processing continues uninterrupted: a log that fails to build is dropped without costing the others, and `saveComponentLogs` never throws back to the component — failures are written to the Apex debug log

## Runtime Information

The system captures comprehensive runtime context:

| Metric Type | Examples                           |
| ----------- | ---------------------------------- |
| Performance | Page load, DOM events, Paint times |
| Environment | User agent, Platform, Language     |
| Network     | Connection type, Speed, RTT        |
| Memory      | Heap usage, Limits                 |
| Device      | Form factor, Screen dimensions     |

## Related Classes

The TritonLwc class works with several wrapper classes:

* [ComponentLog](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonlwc/componentlog.md) - Main wrapper for LWC log data
* [Component](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonlwc/component.md) - Component context information
* [Error](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonlwc/error.md) - Error details structure
* [RuntimeInfo](https://triton.pharos.ai/methods-reference/apex-methods-reference/tritonlwc/runtimeinfo.md) - Runtime metrics and context
