⚡ Scan Your Apex Code for Performance Issues Using ApexGuru

ApexGuru is a Salesforce capability (integrated into the Salesforce Code Analyzer VS Code extension) that surfaces performance-related issues in your Apex and explains how to fix them—right inside your editor.

🧭 What you’ll learn

  • What ApexGuru is and when to use it
  • One-time setup in VS Code
  • How to run a scan on a single Apex class
  • How to read the results (and act on them)
  • Common “why don’t I see the command?” gotchas

🚀 Quick Start (TL;DR)

  1. Make sure ApexGuru is supported and activated in the org you’ll use.
  2. In VS Code, authorize that org.
  3. Right-click an Apex .cls file → SFDX: Scan Selected File for Performance Issues With ApexGuru.
  4. Review violations in Problems and inline underlines → hover to read the guidance and suggested code.

🤖 What is ApexGuru (in 20s)?

ApexGuru uses AI/ML to detect performance pitfalls in Apex (e.g., inefficient loops, SOQL/DML patterns, bulkification concerns). It runs via the Salesforce Code Analyzer extension and shows the findings inline with explanations and suggested code.

✅ Unlike general Code Analyzer rules, ApexGuru requires you to authorize an org where ApexGuru is activated.


🛠️ One-time Setup in VS Code

1) Confirm org support & activation

  • Ensure your target Salesforce org supports ApexGuru and it’s activated.
  • (If unsure, check your internal org enablement or documentation like “ApexGuru Insights.”)

2) Authorize the org in VS Code

  • Open the Command PaletteSFDX: Authorize an Org.
  • Choose how you log in (e.g., Project Default, or Sandbox for https://test.salesforce.com).
  • Enter an alias, e.g., apexguru.
  • Complete the browser login → look for Authentication Successful.
  • Close the browser tab and return to VS Code.

🔎 Tip: Your project should be a valid Salesforce DX project (has sfdx-project.json).


🧪 Run Your First Scan

  1. In VS Code Explorer, right-click a single Apex .cls file.
  2. Choose SFDX: Scan Selected File for Performance Issues With ApexGuru.
  3. Watch the progress note in VS Code’s status area.
  4. When finished, see how many violations were found.

ℹ️ You can scan one file at a time. If you right-click a folder or multi-select files, this command won’t appear.


🧐 Reading the Results

  • Inline underlines mark suspicious code.
  • Open the PROBLEMS tab to see a list of findings.
  • Hover a finding in the editor to see:
    • A plain-English explanation of the issue
    • (Often) suggested code you can copy-paste and adapt

🎯 Treat suggestions as a starting point. Validate logic, bulk safety, and test coverage before committing.


🧯 “I don’t see the command” Checklist

If SFDX: Scan Selected File for Performance Issues With ApexGuru doesn’t show up:

  • You right-clicked a folder or multiple files (ApexGuru scans one file).
  • The target org doesn’t support/activate ApexGuru yet.
  • The org wasn’t authorized correctly in VS Code (re-authorize and retry).
  • You’re not right-clicking an Apex .cls file.
  • Ensure Salesforce Code Analyzer extension is installed and updated.

✅ Good Practices

  • Scan early, scan often: run ApexGuru during PR reviews or pre-merge checks (manual runs from VS Code still help you catch regressions).
  • Pair with unit tests: when you accept a suggestion, add/adjust tests to assert performance-friendly behavior (bulk, limits).
  • Document the why: when you change code based on a suggestion, leave a short comment explaining the design intent.

📌 Recap

  • ApexGuru lives inside Salesforce Code Analyzer (VS Code).
  • It requires an authorized org where ApexGuru is activated.
  • You scan one Apex file at a time.
  • Findings show inline + in PROBLEMS with human-readable explanations and suggested fixes.

📣 Share & Discuss

Have a pattern that ApexGuru frequently flags in your codebase? Drop it in the comments—I’ll compile a follow-up with real-world examples from the community.

References:

  1. Scan Your Apex Code for Performance Issues Using ApexGuru
  2. GA : ApexGuru Integration with Code Analyzer