/sf-flow-coverage:flowcov-fix-testsfrom sf-flow-coverage
Use when the user asks to fix, finish, or get passing the Apex tests that `sf flowcov scaffold` generated for Salesforce Flows, to "work through the flowcov TODOs", or to raise Flow test coverage toward "Deploy processes and flows as active" in a Salesforce DX project. Generates or reads the tests with the sf-flow-coverage CLI plugin, fills in their TODOs from the Flow metadata, deploys and runs them in a sandbox or scratch org, fixes what fails because of the test's data, and reports what needs a change in the org instead. Requires the Salesforce CLI with the sf-flow-coverage plugin and an authenticated sandbox or scratch org.
Ships in sf-flow-coverage. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
sf flowcov scaffold writes a starter Apex test for each Flow. It fills in what it can work out from the Flow and the org's metadata, and leaves a TODO for the rest. This skill finishes the job: it reads each test's TODOs, fills them in from the Flow's metadata, runs the tests, and fixes the ones that fail because of the test's data.
Some failures can't be fixed in a test, because they come from how the org is set up: a field the test user can't see, an approval process, a record type the user can't use. Report those for the user to fix in the org instead of working around them.
sf data query -q "SELECT IsSandbox FROM Organization" -o <org> --json. If IsSandbox is false, stop and tell the user. A scratch org reports true.*_FlowTest.cls). Never change the Flow under test, other Apex, validation rules, permissions, or any other metadata, in the project or in the org.Don't catch exceptions so that a test passes. Catching the error the Flow is meant to raise is fine, when the test asserts that it was raised and what it says:
try {
update testRecord;
Assert.fail('Handover_Items_Not_Closed should block this save');
} catch (DmlException e) {
Assert.isTrue(e.getMessage().contains('Close all handover items'), e.getMessage());
}
Catch only that exception type, and assert the message.
Don't remove or weaken an assertion only because it fails. Check the expected value against the Flow's elements first.
Don't use @IsTest(SeeAllData=true) or hard-coded record Ids.
scaffold with --force only for classes the user hasn't edited by hand, or when the user asks. The same goes for a test class already in the org: see "Deploy conflicts" in Step 4.Run each sf command on its own. Don't chain several in one shell line with && or pipes: on Windows, a chained sf command can fail with 'C:\Program' is not recognized when it's run from Git Bash.
sfdx-project.json, and note its default package directory.sf plugins inspect sf-flow-coverage. If it isn't, ask the user before running sf plugins install sf-flow-coverage.Run scaffold with --json for the Flows the user named, or for every uncovered Flow:
sf flowcov scaffold --flow <FlowName> --target-org <org> --json
sf flowcov scaffold --uncovered --target-org <org> --json
The result lists each created class with its TODOs:
{
"flowName": "Job_Flow",
"className": "Job_Flow_FlowTest",
"path": "...",
"todos": [{ "method": "runsFlowOnCreate", "kind": "validation rule", "text": "validation rule: Needs_Parent (...)" }]
}
method comes from the class header and applies to the whole class.kind says what the TODO is about. See references/todos.md for what to do with each kind.skipped. Work on those files as they are.For each class with TODOs, one class at a time:
Read the test class and the Flow's .flow-meta.xml. Its path is under the package directory, in a flows folder, named <FlowName>.flow-meta.xml.
For each TODO, follow references/todos.md. Read whatever metadata the TODO points to, such as the validation rule's formula or the lookup filter, and set the field values that meet it.
Where the class only checks that the record was saved, add assertions for what the Flow does:
Base them on the Flow's elements for the data the test sets. Leave a TODO for an outcome you can't work out.
Remove each TODO comment once it's handled. Leave the TODOs that need a change in the org, and add the reason.
Update the class header. Once no TODOs are left for you, remove its line "Replace the TODOs with real data and assertions on what the Flow does." In its place, briefly say what the tests cover, and anything they can't, such as a fault path no test can trigger.
Deploy only the classes you changed, then run them:
sf project deploy start --source-dir <path/to/Class_FlowTest.cls> --target-org <org> --wait 10
sf apex run test --class-names <Class_FlowTest> --target-org <org> --code-coverage --result-format json --wait 10
--code-coverage makes Salesforce record the Flow coverage these tests give.
Deploy conflicts. If the deploy stops because the class in the org differs from the one you're deploying, don't add --ignore-conflicts straight away:
sf project retrieve start --metadata ApexClass:<Class_FlowTest> --target-org <org> --target-metadata-dir <scratch folder> --unzip.--ignore-conflicts only when one of these is true:
For each failing method, read the error and look it up in references/failures.md:
Finish with a summary:
| Class | Result | What changed | Needs in the org |
|---|---|---|---|
Job_Flow_FlowTest | Passing | Set the parent project the validation rule needs | |
Case_Flow_FlowTest | Org change needed | Field-level security on Case.Secret__c for the test user |
Then show where coverage stands with sf flowcov readiness --target-org <org>, and list the org changes that would make the remaining tests pass.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub mcarvin8/sf-flow-coverage --plugin sf-flow-coverage