agentleFS
jiten-singh-shahijiten-singh-shahi/salesforce-claude-code/.cursor/skills/sf-build-fix/SKILL.md

sf-build-fix

Skill15 starsChanged 7 months agoMITView on GitHub

Auto-fix Salesforce build errors — Apex compilation, metadata conflicts, dependencies, test failures. Use when build errors block deployment. Do NOT use for writing new features or refactoring.

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 12 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When Apex compilation errors are blocking a deployment

    line 16
  2. Distinctive:

    When metadata conflicts prevent deploying to a target org

    line 17
  3. Distinctive:

    When test failures need to be resolved before deployment validation passes

    line 18
  4. Distinctive:

    When dependency resolution is needed (missing objects, fields, or class references)

    line 19
  5. Very specific:

    When you receive build errors from sf project deploy and need systematic resolution

    line 20
  6. Distinctive:

    Run a dry-run deployment or check compiler output:

    line 26
  7. Distinctive:

    If the user pasted error output directly, use that instead.

    line 32
  8. Distinctive:

    Read the file at the reported line number

    line 52
  9. Very specific:

    Verify it compiles: sf project deploy validate --metadata "ApexClass:<ClassName>" --target-org <org>

    line 55
  10. Distinctive:

    When deploying multiple metadata types, follow this order:

    line 82
  11. Very specific:

    When sf project deploy reports conflicts:

    line 95
  12. Distinctive:

    Merge: Keep production changes, layer your modifications on top

    line 99
  13. Distinctive:

    Do NOT refactor while fixing builds

    line 105
  14. Distinctive:

    Do NOT change architecture

    line 106
  15. Distinctive:

    If a fix introduces new errors, revert and try a different approach

    line 107

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Build Fix — Salesforce Build and Deployment Error Resolution

Fix build and deployment errors incrementally. Parse error output, classify issues, fix one at a time, re-validate.

Reference: @../_reference/DEPLOYMENT_CHECKLIST.md

When to Use

  • When Apex compilation errors are blocking a deployment
  • When metadata conflicts prevent deploying to a target org
  • When test failures need to be resolved before deployment validation passes
  • When dependency resolution is needed (missing objects, fields, or class references)
  • When you receive build errors from sf project deploy and need systematic resolution

Workflow

Step 1 — Capture Errors

Run a dry-run deployment or check compiler output:

sf project deploy validate --target-org <alias> --json 2>&1

If the user pasted error output directly, use that instead.

Step 2 — Parse and Classify

Group errors by type and fix in this dependency order:

PriorityError TypeFix Strategy
1Missing object/field metadataDeploy metadata first -- objects before classes
2Missing class/interface referenceCheck spelling, verify class exists, check API version
3Type mismatchCast explicitly, check null handling, verify generic types
4Method signature changedUpdate all callers, check for overloaded methods
5Metadata conflictRetrieve latest from org with sf project retrieve start, merge
6Test failureFix test data setup, update assertions, check @TestSetup
7Governor limit in testAdd Test.startTest()/stopTest(), reduce data volume

Step 3 — Fix One at a Time

For each error:

  1. Read the file at the reported line number
  2. Understand the context (class, method, trigger)
  3. Apply the minimal fix
  4. Verify it compiles: sf project deploy validate --metadata "ApexClass:<ClassName>" --target-org <org>

Step 4 — Re-validate

After all fixes:

sf project deploy validate --target-org <alias> --test-level RunLocalTests

Common Apex Compilation Errors

Error Message PatternRoot CauseFix
Variable does not exist: XUndeclared variable or field removedDeclare variable or check field API name
Method does not exist or incorrect signatureWrong parameter types or method renamedCheck method signature in target class
Illegal assignment from X to YType mismatchAdd explicit cast or fix generic type
Non-void method might not return a valueMissing return in a branchAdd return statement to all code paths
Compile Error: unexpected tokenSyntax errorCheck line above the reported line
System.NullPointerException (test)Null reference in test setupAdd null checks or fix @TestSetup
Duplicate value found (test)Test data collisionUse unique identifiers, avoid SeeAllData
FIELD_CUSTOM_VALIDATION_EXCEPTION (test)Validation rule blocking test DMLPopulate all required fields in test data
MIXED_DML_OPERATION (test)Setup + non-setup DML in same transactionUse System.runAs() in tests or @future in production
UNABLE_TO_LOCK_ROW (test)Concurrent test data conflictsUse unique records per test method

Dependency Resolution Order

When deploying multiple metadata types, follow this order:

  1. Custom Objects and Fields
  2. Record Types and Page Layouts
  3. Apex Classes (utilities and base classes first)
  4. Apex Triggers
  5. Lightning Web Components
  6. Flows (Process Builder is deprecated since Winter '23 -- migrate to Flows)
  7. Permission Sets and Profiles
  8. Apex Test Classes (verify at end)

Metadata Conflict Resolution

When sf project deploy reports conflicts:

  1. Retrieve current org state: sf project retrieve start --metadata <type>:<name>
  2. Compare: diff force-app/main/default/<path> <retrieved-path>
  3. Merge: Keep production changes, layer your modifications on top
  4. Do not force-overwrite production metadata without understanding the diff

Rules

  • Fix one error at a time -- cascade fixes often resolve multiple issues
  • Do NOT refactor while fixing builds
  • Do NOT change architecture
  • If a fix introduces new errors, revert and try a different approach

Examples

sf-build-fix
sf-build-fix Fix the Apex compile errors from this deployment output: <paste errors>
sf-build-fix The AccountService.cls has a type mismatch on line 47
sf-build-fix Resolve the metadata conflicts blocking our deployment to UAT

Related

  • Constraints: sf-deployment-constraints -- deployment safety rules and validation gates

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.