apex-test

apex-test is a command for Claude Code from bhanu91221/sfdx-iq. It costs 13 tokens per session (1,888 once invoked), scanned A, original, MIT.

A command for creating or improving Apex test classes, which are automated tests for Salesforce code.

In plain words
What is it for?
Creating tests, improving coverage to a chosen level, testing 200 or more records, and adding HTTP callout mocks.
Why use it?
It helps find missing test cases and target coverage for different code paths, including bulk records and HTTP callouts.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the sfdx-iq plugin — 20 commands, 7 agents shipped together

Good fit Creating tests, improving coverage to a chosen level, testing 200 or more records, and adding HTTP callout mocks.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/bhanu91221/sfdx-iq/apex-test
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/bhanu91221/sfdx-iq

Made for: Claude Code.

Or install sfdx-iq, the plugin that ships this one along with the rest of its 20 commands, 7 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for apex-test

README.md
[![agentmods](https://agentmods.dev/badge/commands/bhanu91221/sfdx-iq/apex-test.svg)](https://agentmods.dev/commands/bhanu91221/sfdx-iq/apex-test)
Your own site
<a href="https://agentmods.dev/commands/bhanu91221/sfdx-iq/apex-test"><img src="https://agentmods.dev/badge/commands/bhanu91221/sfdx-iq/apex-test.svg" alt="Measured on agentmods" height="20"></a>
Per session 13 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,888 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00013 $0.01888
Opus 5 $0.00006 $0.00944
Sonnet 5 $0.00003 $0.00378
Haiku 4.5 $0.00001 $0.00189

Measured 8d ago against content hash b0885bcb58c3, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

apex-test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/apex-test.md · 234 lines

How it starts

The opening of the file, as written. The whole thing — 234 lines — stays where its author put it; the contents beside it link to each section on GitHub.

/apex-test

Create a new Apex test class, or improve coverage for an existing one, following Salesforce best practices.

Usage

/apex-test MyClass.cls                  Find or create test class for MyClass
/apex-test --coverage MyClass.cls       Show current coverage + improve to 90%
/apex-test --coverage MyClass.cls 80%  Improve to specific target coverage level
/apex-test --bulk MyClass.cls          Focus on bulk (200+ record) test scenarios
/apex-test --mock MyClass.cls          Add HttpCalloutMock for all callout methods

Workflow

Step 1: Identify Target Class

  • If a file path or class name is given, use that
  • If none given, check git diff --name-only HEAD for changed .cls files (non-test)
  • If no changed files, ask: "Which class would you like me to write tests for?"

Step 2: Read Source + Find Existing Tests

  1. Read the source class fully — understand all public methods, logic branches, error paths
  2. Search for existing test class: <ClassName>Test.cls in force-app/**/classes/
  3. If test class exists: read it and identify untested paths
  4. If no test class: create from scratch

Step 3: Analyze Coverage Gaps

For each public method in the source class:

  • Identify: happy path, bulk path (200 records), null/empty input, negative/error path
  • Check existing tests — which paths are already covered?
  • For --coverage: note current % and identify the highest-impact untested lines

Step 4: Generate / Improve Tests

Test class standards:

@isTest
private class AccountServiceTest {

    @TestSetup
    static void setup() {
        // Always use TestDataFactory for test data — never inline record creation
        List<Account> accounts = TestDataFactory.createAccounts(200, 'Test Corp');
        insert accounts;
    }

    @isTest
    static void testProcessAccounts_happyPath() {
        List<Account> accounts = [SELECT Id, Industry FROM Account LIMIT 10];
        
        Test.startTest();
        AccountService.processAccounts(new Map<Id, Account>(accounts).keySet());
        Test.stopTest();
        
        // Assert expected outcome
        List<Account> updated = [SELECT Id, Status__c FROM Account WHERE Id IN :accounts];
        for (Account acc : updated) {
            Assert.areEqual('Active', acc.Status__c, 'Status should be Active after processing');
        }
    }

    @isTest
    static void testProcessAccounts_bulk() {
        // Bulk test — always test with 200 records
        List<Account> accounts = [SELECT Id FROM Account]; // setup created 200
        Assert.areEqual(200, accounts.size(), 'Setup should create 200 accounts');
        
        Test.startTest();
        AccountService.processAccounts(new Map<Id, Account>(accounts).keySet());
        Test.stopTest();
        
        // Verify all 200 processed
        Integer processed = [SELECT COUNT() FROM Account WHERE Status__c = 'Active'];
        Assert.areEqual(200, processed, 'All 200 accounts should be processed');
    }

    @isTest
    static void testProcessAccounts_emptyInput() {
        Test.startTest();
        AccountService.processAccounts(new Set<Id>()); // Should not throw
        Test.stopTest();
        // No exception = pass
    }

    @isTest
    static void testProcessAccounts_nullInput() {
        Test.startTest();
        try {
            AccountService.processAccounts(null);
            Assert.fail('Should throw for null input');
        } catch (IllegalArgumentException e) {
            Assert.isTrue(e.getMessage().contains('null'), 'Error message should mention null');
        }
        Test.stopTest();
    }
}

Read the full file on GitHub · 234 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 234 lines · 13 tokens per session scan A b0885bcb58c3

Subscribe to this mod's changes

apex-test is a command published in the GitHub repository bhanu91221/sfdx-iq (2 stars, last pushed 3mo ago), licensed MIT. It adds 13 tokens to every session and 1,888 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.