> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moxycode.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Analysis

> MoxyCode analyses your Apex and LWC code on every save and flags issues before they become deployment errors.

<iframe width="100%" height="400" src="https://www.youtube.com/embed/YOUR_VIDEO_ID" title="MoxyCode Code Analysis" frameBorder="0" allowFullScreen />

MoxyCode analyses your code every time you open a file and every time you save. Issues are flagged inline — highlighted lines in the editor and CodeLens links above each affected line — so you catch problems before they fail a deployment.

## How it works

1. Open any supported Apex or LWC file in VS Code
2. MoxyCode analyses the file automatically
3. Affected lines are highlighted in the editor
4. A **MoxyCode: 💡 Explain & Fix** CodeLens link appears above each flagged line
5. Hover over a highlighted line to see a quick summary of the issue

<Note>
  Analysis runs automatically on every save — highlights and CodeLens links update instantly as you fix issues.
</Note>

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/moxycode/images/code-analysis-inline.png" alt="MoxyCode highlighted lines and CodeLens links in the editor" />
</Frame>

## Explain & Fix

Click **MoxyCode: 💡 Explain & Fix** above any flagged line to open the **MoxyCode — Code Analysis** panel for that issue.

The panel shows:

* The issue title and category (Security / Governor Limit / Code Quality)
* Confidence and risk ratings
* A plain-English explanation of the issue
* **Fixed Code** — the corrected version of your file
* **What Changed** — a summary of exactly what was modified and why
* **Overall Summary** — confidence and risk for the fix

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/moxycode/images/code-analysis-explain-fix.png" alt="MoxyCode Code Analysis panel for a single issue" />
</Frame>

### Free plan

On the Free plan, **Explain & Fix** shows the full analysis and fixed code. The **Apply Fix** button is locked — copy the fixed code from the panel and apply it manually.

Each **Explain & Fix** click uses 1 of your 5 daily AI requests.

<Note>
  The 5 daily AI request limit is shared across the entire product — Explain & Fix clicks, deploy panel explains, and chat messages all count toward this limit.
</Note>

### Pro

On Pro, click **Apply Fix** to apply the change. The button changes to **Fix Applied** and a notification appears:

**"MoxyCode: Fix applied — changed lines highlighted in green. Save to confirm."**

Changed lines are highlighted in green in your editor. From the notification you can:

* Click **Save File** to accept the changes
* Click **Undo Fix** to revert immediately

## Pro — Explain & Fix All Warnings

On Pro, a **MoxyCode: 💡 Explain & Fix All Warnings (n)** CodeLens link appears at the top of the file — where `n` is the total number of warnings found. Click it to analyse and fix every issue in the file at once.

The Code Analysis panel opens with:

* Every issue listed with its category, confidence, and explanation
* **Fixed Code** — the fully corrected file
* **What Changed** — every issue summarised in one list
* **Overall Summary** — combined confidence and risk across all fixes
* **Apply Fix** — applies all changes in one click. Changed lines highlight green — click **Save File** in the notification to confirm or **Undo Fix** to revert

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/moxycode/images/code-analysis-fix-all.png" alt="MoxyCode Code Analysis panel showing all warnings fixed at once" />
</Frame>

<Note>
  Explain & Fix All Warnings is not visible to Free plan users. Upgrade to Pro to access it.
</Note>

## The Code Analysis panel

Both **Explain & Fix** and **Explain & Fix All Warnings** open the same **MoxyCode — Code Analysis** panel. It includes a chat input at the bottom — use it to ask follow-up questions about the issue, request an alternative fix, or understand the Salesforce context in more detail.

Each chat message uses 1 of your 5 daily AI requests on the Free plan.

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/moxycode/images/code-analysis-panel-chat.png" alt="MoxyCode Code Analysis panel with chat input" />
</Frame>

<Note>
  Chat messages are limited to 4,000 characters per message to ensure fair usage for all users.
</Note>

## What MoxyCode catches

MoxyCode analyses your code for governor limit violations, security issues, LWC best practices, and code quality problems across Apex and LWC files.

<Card title="Code Analysis Rules" icon="list" href="/reference/code-analysis-rules">
  View the full list of rules, severity levels, and what each one catches
</Card>

## Supported file types

| Extension  | Type              |
| ---------- | ----------------- |
| `.cls`     | Apex class        |
| `.trigger` | Apex trigger      |
| `.js`      | LWC JavaScript    |
| `.html`    | LWC HTML template |

## Common issues

<AccordionGroup>
  <Accordion title="No highlighted lines or CodeLens appearing">
    MoxyCode analysis runs on file open and on save. Try saving the file once to trigger analysis. If nothing appears, run **Developer: Reload Window** from the Command Palette and reopen the file.
  </Accordion>

  <Accordion title="Explain & Fix All Warnings not visible">
    Explain & Fix All Warnings is a Pro feature and is not shown to Free plan users. On the Free plan, use **MoxyCode: 💡 Explain & Fix** above each individual flagged line.
  </Accordion>

  <Accordion title="Apply Fix button is locked">
    Apply Fix requires a Pro plan. On the Free plan, the full analysis and fixed code are still shown in the Code Analysis panel — copy the fixed code and apply it manually to your file.
  </Accordion>

  <Accordion title="Hit the 5 request limit">
    The 5 daily AI request limit on the Free plan is shared across the entire product. The limit resets 24 hours after your 5th request was made. Upgrade to Pro for unlimited requests.
  </Accordion>

  <Accordion title="Suggested fix looks incorrect">
    Review the confidence and risk ratings in the Code Analysis panel. For issues flagged as High Risk or Low Confidence, use the explanation to understand the problem and apply the fix manually. Use the chat input at the bottom of the panel to ask follow-up questions.
  </Accordion>
</AccordionGroup>

<CardGroup cols={2}>
  <Card title="Fix Deployment Errors" icon="wrench" href="/workflows/fix-deployment-errors">
    Fix errors after a failed deployment
  </Card>

  <Card title="Deploy to Org" icon="cloud-arrow-up" href="/workflows/deploy-to-org">
    Deploy Apex and LWC files directly from VS Code
  </Card>
</CardGroup>
