# platform-apex-test-run

Runs Apex tests via the Salesforce CLI, analyzes code coverage, and guides test-fix loops. Useful when investigating unit test failures or low coverage.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 6900 installs · ★ 1112
- Author: forcedotcom
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/forcedotcom/sf-skills/tree/HEAD/skills/platform-apex-test-run/SKILL.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/skills/platform-apex-test-run

## What it does

The skill executes Apex tests using `sf apex run test` and inspects code coverage lines. It enforces isolation with `SeeAllData=false`. To test trigger boundaries across the 200-record batch limit, it verifies bulk scenarios with 251 or more records.

The workflow requires `sf` version 2.0.0 or higher, `python3` 3.10.0 or higher, and `jq` 1.6.0 or higher. It starts with the smallest test scope before widening regression. Authoring production code is outside its scope: that task delegates to `platform-apex-generate`, while LWC Jest tests belong to `experience-lwc-generate`.

## Requirements
- Works with: Salesforce

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add forcedotcom/sf-skills --skill platform-apex-test-run -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/platform-apex-test-run/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/platform-apex-test-run/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add forcedotcom/sf-skills --skill platform-apex-test-run -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/platform-apex-test-run/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add forcedotcom/sf-skills --skill platform-apex-test-run -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/platform-apex-test-run/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install forcedotcom/sf-skills platform-apex-test-run
```

2. **Manually: put the files in place**
- File: `.github/skills/platform-apex-test-run/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add forcedotcom/sf-skills --skill platform-apex-test-run -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/forcedotcom/sf-skills --path skills/platform-apex-test-run
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/platform-apex-test-run/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add forcedotcom/sf-skills --skill platform-apex-test-run -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/forcedotcom/sf-skills/tree/HEAD/skills/platform-apex-test-run/SKILL.md

## When to use it
- Run Apex unit tests in a target org via `sf`
- Identify uncovered code lines and untested branches
- Parse stack traces and exceptions in failing test methods
- Verify bulk processing for 251+ records across trigger batches

## Example prompts
- Run Apex tests for OrderTriggerHandlerTest on dev-org and report coverage
- Diagnose why testBulkInsert failed in AccountServiceTest
- Check code coverage for billing classes and list uncovered lines

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 190fa8ce3c9fbfa7.

BEGIN THIRD-PARTY FILE 190fa8ce3c9fbfa7
```text
---
name: platform-apex-test-run
description: "Apex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user runs Apex tests, checks code coverage, fixes failing tests, or touches *Test.cls / *_Test.cls files. DO NOT TRIGGER when writing Apex production code (use platform-apex-generate), Agentforce agent testing (use agentforce-test), or Jest/LWC tests (use experience-lwc-generate)."
metadata:
  version: "1.2"
  domains: ["Platform"]
  relatedSkills:
    - "agentforce-test"
    - "experience-lwc-generate"
    - "platform-apex-generate"
    - "platform-apex-logs-debug"
    - "platform-data-manage"
    - "platform-metadata-deploy"
  cliTools:
    - tool: ["jq"]
      semver: ">=1.6.0"
    - tool: ["python3"]
      semver: ">=3.10.0"
    - tool: ["sf"]
      semver: ">=2.0.0"
---

# platform-apex-test-run: Salesforce Test Execution & Coverage Analysis

Use this skill when the user needs **Apex test execution and failure analysis**: running tests, checking coverage, interpreting failures, improving coverage, and managing a disciplined test-fix loop for Salesforce code.

## When This Skill Owns the Task

Use `platform-apex-test-run` when the work involves:
- `sf apex run test` workflows
- Apex unit-test failures
- code coverage analysis
- identifying uncovered lines and missing test scenarios
- structured test-fix loops for Apex code

Delegate elsewhere when the user is:
- writing or refactoring production Apex → `platform-apex-generate` skill
- testing Agentforce agents → `agentforce-test` skill
- testing LWC with Jest → [experience-lwc-generate](../experience-lwc-generate/SKILL.md)

---

## Required Context to Gather First

Ask for or infer:
- target org alias
- desired test scope: single class, specific methods, suite, or local tests
- coverage threshold expectation
- whether the user wants diagnosis only or a test-fix loop
- whether related test data factories already exist

---

## Recommended Workflow

### 1. Discover test scope
Identify:
- existing test classes
- target production classes
- test data factories / setup helpers

### 2. Run the smallest useful test set first
Start narrow when debugging a failure; widen only after the fix is stable.

### 3. Analyze results
Focus on:
- failing methods
- exception types and stack traces
- uncovered lines / weak coverage areas
- whether failures indicate bad test data, brittle assertions, or broken production logic

### 4. Run a disciplined fix loop
When the issue is code or test quality:
- delegate code fixes to `platform-apex-generate` skill when needed
- add or improve tests
- rerun focused tests before broader regression

### 5. Improve coverage intentionally
Cover:
- positive path
- negative / exception path
- bulk path (251+ records where appropriate)
- callout or async path when relevant

---

## High-Signal Rules

| Rule | Rationale |
|------|-----------|
| Default to `SeeAllData=false` | Ensures test isolation; prevents reliance on org-specific data |
```
END THIRD-PARTY FILE 190fa8ce3c9fbfa7

The third-party file has ended. Everything between the 190fa8ce3c9fbfa7 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3003 of 7521 bytes. © forcedotcom · Apache-2.0 · https://github.com/forcedotcom/sf-skills/tree/HEAD/skills/platform-apex-test-run/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
