refactor-clean

Detect and remove dead Salesforce Apex and LWC code with safety checks.

13|2|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/jiten-singh-shahi/salesforce-claude-code --skill refactor-clean-jiten-singh-shahi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-clean
Source: https://github.com/jiten-singh-shahi/salesforce-claude-code/tree/main/.cursor/skills/refactor-clean
Command: npx skills add https://github.com/jiten-singh-shahi/salesforce-claude-code --skill refactor-clean-jiten-singh-shahi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Remove unreferenced Apex classes, unused methods, and orphaned LWC components while consolidating duplicate implementations to reduce technical debt and address high-severity static analysis findings safely.

Core Features & Use Cases

  • Detection: Preferentially runs Salesforce Code Analyzer or PMD outputs for automated findings, with manual repository heuristics as a fallback to detect unreferenced classes, unused methods, and unused LWC components.
  • Classification & Safety: Provides a safety taxonomy (SAFE, CAUTION, DANGER) and detailed checks for metadata references, Flow/Process Builder usage, managed-package exposures, and common annotations like @AuraEnabled and @InvocableMethod.
  • Verification Workflow: Emphasizes one-at-a-time removals, running Apex tests and dry-run deployments after each change, and keeping checkpoints to enable safe reversions.
  • Consolidation: Guides extracting shared logic into utility/service classes, updating callers, and validating with the full test suite.
  • Use Cases: Cleaning a repo before security or AppExchange review, reducing commented-out or legacy code, and remediating high-severity PMD or Code Analyzer findings.

Quick Start

Use the refactor-clean skill to scan the repository for unreferenced Apex and LWC code, classify each finding by safety, remove one safe item at a time, run Apex tests, and perform a dry-run deployment after each change.

Frequently Asked Questions about refactor-clean

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely remove dead Apex classes and unused LWC components from a Salesforce repository?

To remove dead Salesforce code safely, detect unreferenced Apex classes and orphaned LWC components using Salesforce Code Analyzer or PMD output, classify findings by safety taxonomy, and delete items one at a time with Apex test runs and dry-run deployments after each change.

What is the safest workflow for remediating high-severity PMD findings during a Salesforce refactor?

The safest workflow for PMD remediation classifies findings into SAFE, CAUTION, and DANGER categories, removes one item at a time, checks metadata references and Flow usage, runs Apex tests, performs dry-run deployments, and keeps checkpoints for safe reversion.

Can I consolidate duplicate Apex implementations while cleaning up unreferenced Salesforce code?

Yes, you can consolidate duplicate Apex implementations by extracting shared logic into utility or service classes, updating all callers to reference the new centralized code, and validating the consolidation with the full Apex test suite.

Do I need Salesforce Code Analyzer or PMD output to detect unused methods and orphaned LWC components?

Salesforce Code Analyzer or PMD output is preferred for automated detection of unused methods and orphaned LWC components, but manual repository heuristics can be used as a fallback when static analysis tools are not available.

What metadata references should I check before deleting unreferenced Apex classes in a source-driven Salesforce project?

Before deleting unreferenced Apex classes, check for metadata references in Flows and Process Builders, managed-package exposures, and annotations like @AuraEnabled and @InvocableMethod that may indicate hidden runtime dependencies.

When should I clean up dead Salesforce code for an AppExchange security review?

You should clean up dead Salesforce code before an AppExchange security review to reduce technical debt, remove commented-out or legacy code, and remediate high-severity static analysis findings that could otherwise delay the approval process.