A code scanner for Salesforce means adding static analysis to your org and your deployment pipeline so that Apex, Lightning Web Components, Visualforce and metadata are checked for security, performance and quality problems before they reach production. The practical way to do it is to install Salesforce Code Analyzer (the official CLI plugin, formerly the Salesforce CLI Scanner plugin), run it locally against your source, then wire the same command into your CI job. Nothing needs to be purchased; you need the Salesforce CLI, a Java runtime, and a project with your source pulled down.

What You'll Need

  • A workstation with Node.js and npm installed (the Salesforce CLI is distributed through npm).
  • The Salesforce CLI (sf) installed and signed in to the org or connected to your repository.
  • A Java runtime (JRE) available on your PATH, because several of the engines the analyzer bundles are Java-based.
  • A local Salesforce project with source retrieved, for example via sf project retrieve start, or a Git clone of your repository.
  • Optional but recommended: a CI service (GitHub Actions, GitLab CI, Jenkins, Azure DevOps) where you can run the same command on every pull request.

Step-by-Step

  1. Confirm the CLI is installed and current. Run sf --version. If the command is not found, install the CLI from Salesforce's official installer or via npm, then reopen your terminal. Update with sf update so the plugin ecosystem is consistent.
  2. Install the Code Analyzer plugin. Run sf plugins install @salesforce/sfdx-scanner (or the current official plugin name shown in Salesforce's Code Analyzer documentation if it has been renamed). Verify with sf plugins and check that the scanner appears in the list.
  3. Check Java. Run java -version. If it fails, install a supported JRE and set JAVA_HOME. Without Java, the PMD and other Java-backed engines will fail while the JavaScript engines still run, which produces confusing partial results.
  4. Open a Salesforce project. Change into the project root (the folder containing sfdx-project.json or sf-project.json). The scanner resolves source from the project structure, so running it from the wrong folder returns zero files scanned.
  5. Run a first scan. Use sf scanner run with a target, for example sf scanner run --target "force-app". Add --format table for a readable console summary or --format json (or sarif) for machine-readable output. A first run on a medium project can take several minutes because engines initialize.
  6. Read the results by severity. Each finding lists a rule name, severity, file, line and a short description. Start with the highest severity security rules (SOQL injection, CRUD/FLS enforcement, XSS in Visualforce) before style rules; fixing everything at once is not realistic.
  7. Tune the rule set. Create a config file (the scanner supports a YAML/JSON config passed with --config) or use category and severity filters such as --category Security or --severity-threshold 2. Excluding rules you have consciously accepted keeps the report trustworthy; blanket suppression does not.
  8. Add suppressions deliberately. Where a finding is a false positive, use the engine's inline suppression comment (for example a PMD-style @SuppressWarnings annotation or the documented comment syntax) with a short reason. Record suppressions in code review so they are visible.
  9. Wire it into CI. Add a job step that installs the CLI and plugin, then runs the scanner with --format sarif and publishes the SARIF file to your code scanning dashboard. Fail the build on high-severity findings using the severity threshold flag so regressions cannot merge.
  10. Schedule a full-org baseline. Periodically retrieve the full source and scan everything, not just changed files, so legacy classes are not permanently invisible. Store the report as a build artifact for trend comparison.

Common Mistakes

  • Running the scanner outside the project root, which silently scans nothing.
  • Missing Java, so only part of the engines run and the report looks clean when it is incomplete.
  • Scanning only changed files in CI and never establishing a full baseline, leaving old vulnerabilities untouched.
  • Suppressing rules globally to get a green build instead of fixing or narrowly suppressing individual findings.
  • Treating the scanner as a replacement for a security review; it catches patterns, not business-logic flaws.
  • Ignoring the SARIF output and only reading console tables, which makes trend tracking impossible.

Tips

  • Run the scanner before every commit on the files you touched; it is fast on small targets.
  • Keep the plugin updated alongside the CLI, since rule packs change between releases.
  • Agree a severity threshold with your team (for example, block on severity 1 and 2) and document it.
  • Pair the scanner with a linter for LWC and a formatter so style noise does not drown security findings.
  • Review suppression comments in pull requests the same way you review code.

Troubleshooting

If the command is not found, the plugin is not installed or your shell path is stale; reinstall the plugin and reopen the terminal. If the scan reports zero files, confirm you are in the project root and that the target path exists and contains source. If Java-related engines error out, check java -version and JAVA_HOME. If the scan hangs, try a narrower target to isolate the file causing it, and update the plugin. If CI fails only on the scanner step, confirm the CI image has Node, Java and the plugin installed, and that the SARIF output path is writable. If results differ between machines, compare plugin and CLI versions first. If a rule fires on code you believe is safe, verify the rule documentation before suppressing it, and prefer a narrow inline suppression over a global exclusion.

Frequently Asked Questions

Is Salesforce Code Analyzer free?

Yes. It is an official Salesforce CLI plugin distributed through Salesforce's own channels; you install it with the CLI, not from a third-party store.

Does it scan Lightning Web Components?

Yes. It includes JavaScript-oriented engines alongside the Apex and Visualforce engines, so LWC JavaScript files are covered.

Can it block a deployment?

Not by itself. It reports findings; blocking happens when you run it in CI with a severity threshold and fail the job on violations.

Do I need Java?

Yes for the Java-based engines. Without a JRE those engines fail and your results are incomplete.

Where should it run?

Both locally before commit and in CI on every pull request, with a periodic full-source scan as a baseline.

Does it replace a security review?

No. It catches known patterns; business-logic and permission-design flaws still need human review.