# TritonLwc

## 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

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

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/componentInfo.name | LWC      | Functional area          |
| `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:

```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"
}
```

### Related Objects

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

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

## Automatic Behaviors

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

1. **Transaction Management**
   * Creates new transaction if none exists
   * 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 valid enum | Falls back to LWC      |
| Type     | Must be valid enum | Falls back to Frontend |
| Area     | Must be valid enum | Uses component name    |
| Level    | Must be valid enum | Falls back to INFO     |

### 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

## 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](/pharos-triton/methods-reference/apex-methods-reference/tritonlwc/componentlog.md) - Main wrapper for LWC log data
* [Component](/pharos-triton/methods-reference/apex-methods-reference/tritonlwc/component.md) - Component context information
* [Error](/pharos-triton/methods-reference/apex-methods-reference/tritonlwc/error.md) - Error details structure
* [RuntimeInfo](/pharos-triton/methods-reference/apex-methods-reference/tritonlwc/runtimeinfo.md) - Runtime metrics and context


---

# 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/tritonlwc.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.
