> 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/instrumentation-skills/migrate-to-2.0.md).

# Migrate to 2.0

The migrate-to-2.0 skill rewrites 1.x Triton.instance code to the 2.0 static API and flags the immediate-vs-buffered publishing gotcha for you to confirm.

The **migrate-to-2.0** skill automates the mechanical half of [Migrating from Triton 1.x to 2.0](https://triton.pharos.ai/migration.md): it finds every `Triton.instance.*` call and rewrites it to the 2.0 static, builder-first API, using the same method mapping the migration guide documents. Where a rename could quietly change behavior, it **stops and asks** rather than guessing.

This skill is about **converting existing logging**, not adding new logging. If a class has no logging at all, that's a job for [`instrument-apex`](https://triton.pharos.ai/instrumentation-skills/instrument-apex.md). A typical org runs `migrate-to-2.0` first (to clear the 1.x singleton) and `instrument-org` second (to fill the gaps).

{% hint style="info" %}
**Invocation is agent-specific.** In agents that support slash commands (Claude Code, Cursor) you invoke it as `/pharos:migrate-to-2.0 <path>`; in others you point the agent at this skill and a path. See [Running these in your agent](https://triton.pharos.ai/instrumentation-skills.md#running-these-in-your-agent).
{% endhint %}

## Usage

{% code lineNumbers="true" %}

```bash
/pharos:migrate-to-2.0 <path> [--collapse-exceptions] [--collapse-dml] [--deploy]
```

{% endcode %}

| Argument                | Required | Meaning                                                                                                                                            |
| ----------------------- | :------: | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<path>`                |     ✅    | A `.cls`/`.trigger` file, or a directory to sweep.                                                                                                 |
| `--collapse-exceptions` |          | While migrating, collapse hand-assembled error logs down to `.exception(e)`. On by default; pass `--no-collapse-exceptions` to keep them verbatim. |
| `--collapse-dml`        |          | Collapse hand-built bulk-DML failure logs to `.dmlResults(results)`.                                                                               |
| `--deploy`              |          | Deploy after you accept the diff.                                                                                                                  |

## If you vendor Triton as source

When the `Triton*.cls` files live in your repository instead of arriving as a package, the library upgrade is part of the change: 2.0 removes `Triton.instance`, so the library and every caller have to land together. Before rewriting a single caller, the skill has you settle three things:

* **Re-add org-local enum values.** Diff your `TritonTypes` against the incoming 2.0 one; a wholesale copy drops any values you added, and every reference to them stops compiling. (Org-local `Category` values are better retired than preserved — see the note on removed categories in the [migration guide](https://triton.pharos.ai/migration.md#use-real-enum-values).)
* **Sweep the right branch.** The sweep is only as complete as its path and its branch, so run it on the branch that holds every caller.
* **Keep Jest tests out of deploys.** Add `**/__tests__/**` and `**/__mocks__/**` to your project's `.forceignore`. Triton's own repository already ignores them, but a `.forceignore` only governs the project it sits in.

## What it rewrites

The skill applies the [method mapping](https://triton.pharos.ai/migration.md#method-mapping) call by call:

* **Drops `.instance`** — every `Triton.instance.<method>(...)` becomes a static `Triton.<method>(...)`.
* **Moves positional args onto a builder** — old positional signatures become `Triton.t.area(...).summary(...)...` builder chains.
* **Maps level methods correctly** (see the gotcha below).
* **Collapses hand-set error fields** to `.exception(e)` and hand-built DML summaries to `.dmlResults(...)` when the flags allow.
* **Covers every 1.x overload.** It lists every distinct `Triton.instance.<member>` in scope — including property reads such as `TRANSACTION_ID` — and matches each by name *and* argument shape against the mapping table. A call whose exact overload isn't in the table stops the skill; it never guesses a mapping.
* **Sweeps test classes too.** `@isTest` classes are migrated as well: 1.x calls in tests won't compile against 2.0 either.
* **Leaves post-processing alone.** 2.0 sets no post-processing controls on Apex logs, so the narrower set the 1.x warning, debug, and event methods asked for (stack trace, user info, related objects) isn't restated by default. If you want it back, the skill appends `.postProcessing(...)` to those calls and flags each one.
* **Flags ad-hoc taxonomy strings** — `.area('InvoiceSync')` and the like — suggesting a `public static final String` constant per [Custom Classifications](https://triton.pharos.ai/core-concepts/custom-classifications.md), and never editing the shipped `TritonTypes` enums.

## The one gotcha it will not guess on

The migration guide's [behavioral change](https://triton.pharos.ai/migration.md#the-behavioral-change-to-audit-for) is the reason this can't be a blind find-and-replace:

* In 1.x, **bare** methods (`error`, `warning`, `debug`, `event`, `dmlResult`, `integrationError`, and `log`) published **immediately**; `add*` methods **buffered**.
* In 2.0, **all** level methods buffer — you opt into immediate publishing with **`Triton.logNow(...)`**.

So the mapping sends old **bare** methods to `Triton.logNow(...)` and old **`add*`** methods to the buffering level methods. But whether a given old bare call *relied* on immediate publishing is a judgment the skill won't make silently:

{% hint style="danger" %}
**Every old bare-method call is surfaced for confirmation.** For each bare call — `Triton.instance.error(...)` and the other immediate methods — the skill proposes `Triton.logNow(...)` **and** shows you the alternative (buffer + ensure a `flush()` covers it), asking you to confirm. Getting this wrong is how a migrated log silently disappears when a transaction dies before flushing — so the skill refuses to auto-decide it.
{% endhint %}

It also **audits flush coverage** as it goes: now that level methods buffer, any path that logs must also flush (end of handler/`execute`, or a `finally`). Missing flushes are reported alongside the diff.

## Successful DML: check the library, not the call site

1.x `addDMLResult` and `dmlResult` logged only when a row failed. The 2.0 mapping — `Triton.error(Triton.t.area(area).dmlResults(results))` — keeps that by itself: from Triton 2.0.0, `dmlResults(...)` emits nothing when every row succeeded, or the list is null or empty, whichever method it's passed to. So the rewrite is correct as written, with or without a failure check around the call.

What the skill verifies is the library you're migrating **to**. A copy of the 2.0 source vendored before 2.0.0 has no such skip, and there the same rewrite would log an empty ERROR record — and open an issue — on every successful DML. The skill checks the vendored `TritonBuilder.cls` for an `isSuppressed()` method; if it's missing, it has you upgrade the library in the same change rather than adding guards at each call site.

## Example rewrite

{% code lineNumbers="true" %}

```apex
// Before (1.x)
Triton.instance.error(TritonTypes.Area.Accounts, e);
Triton.instance.addDebug(t, TritonTypes.Area.Accounts, 'Rollups done', details);

// After (2.0) — bare error → logNow (confirmed), addDebug → buffering debug
Triton.logNow(Triton.t.area(TritonTypes.Area.Accounts).exception(e));
Triton.debug(Triton.t.type(t).area(TritonTypes.Area.Accounts).summary('Rollups done').details(details));
```

{% endcode %}

## Review and deploy

Before it shows you anything, the skill runs two checks a reviewer reading a diff would miss:

1. **No 1.x member survives** — no `Triton.instance` left in scope, and no half-migrated static call to a method 2.0 doesn't have (`Triton.addError(...)` and friends).
2. **Every enum reference resolves** — each `TritonTypes.<enum>.<value>` exists in the 2.0 `TritonTypes`. This catches removed values such as `TritonTypes.Category.Event`, and org-local values a re-vendored library dropped.

Re-run the first check right before merge, not just at sweep time: a 1.x caller merged in the meantime leaves the branch uncompilable. The [`setup-standards`](https://triton.pharos.ai/instrumentation-skills/setup-standards.md) CI check that fails the build on any `Triton.instance` makes that automatic.

Like every skill here, it then presents a summary — calls migrated, bare-method confirmations pending, the library-version check, collapses applied, flush gaps found, any `.attribute(...)` fallbacks — then the diff, with `yes` / `modify` / `skip`. On `yes` it writes back to the original file; with `--deploy` it runs `sf project deploy start`.

{% hint style="warning" %}
**After deploying, re-assign the permission sets** (`Triton_Read` / `Triton_Write`) so the new 2.0 fields are visible — see the [2.0 release notes](https://triton.pharos.ai/release-notes/2.0.md). And remember the migration guide's [checklist](https://triton.pharos.ai/migration.md#migration-checklist) items a code rewrite can't do for you (permission sets, template placement review).
{% endhint %}

{% hint style="info" %}
**Deploying into an org that still runs 1.x?** `--deploy` fails there, because the migrated code calls 2.0 methods the org doesn't have yet. Follow [Upgrading an Org from 1.x](https://triton.pharos.ai/migration/upgrading-an-org.md) to land it together with 2.0.
{% endhint %}

## What it doesn't touch

The skill rewrites **Apex only**. Check these by hand, using [LWC changes to check](https://triton.pharos.ai/migration.md#lwc-changes-to-check) and the `Log_Level__mdt` item in the [2.0 upgrade notes](https://triton.pharos.ai/release-notes/2.0.md#upgrade-notes):

* **LWC** — removed `CATEGORY` keys (`WARNING`, `DEBUG`, `EVENT`), code that compares area strings, and code that relied on `logNow()` rejecting.
* **Flow XML** — **Log** actions that pass a removed category (`Integration`, `Warning`, `Event`, `Debug`) or a version-suffixed `flowApiName`.
* **`Log_Level__mdt` rules** keyed on a removed category, which silently stop matching.

## Where to go next

* [Migrating from Triton 1.x to 2.0](https://triton.pharos.ai/migration.md) — the conceptual guide this skill automates; read the gotcha section.
* [Audit Logging Coverage](https://triton.pharos.ai/instrumentation-skills/audit-logging.md) — finds the `Triton.instance` usage to point this skill at.
* [Instrument the Org](https://triton.pharos.ai/instrumentation-skills/instrument-org.md) — add logging where there was none, after migration.
* [Buffering, Flushing & Deferred Publishing](https://triton.pharos.ai/core-concepts/buffering-flushing.md) — why the immediate-vs-buffered change matters.
