🧩 Unified Apex Validator
A VS Code extension written in TypeScript that helps you validate, test, and document your Salesforce Apex projects — all in one place. It scans your package.xml, runs tests, checks code quality with Salesforce Code Analyzer (PMD + CPD), and exports slick HTML/PDF reports. You can even plug in Einstein GPT for AI-powered feedback and auto-generated ApexDocs.
🚀 Features
- 🧩 Apex class validation using Salesforce Code Analyzer v5 (PMD + CPD).
- 🔍 Duplicate code detection across your repo.
- 🧪 Apex test execution via Salesforce CLI with coverage metrics.
- 🧠 Optional Einstein GPT insights for risk detection and improvements.
- 🧾 Automatic HTML/PDF report generation with an integrated VS Code viewer.
- 🧭 Sidebar views for reports, logs, and dependency checks.
- ⚡ Quick commands: Validate Apex, Refresh views, Open output folders.
- 🤖 AI-powered ApexDoc generation (beta) with tag enforcement.
- 🧱 Allman-style Apex formatter for .cls/.trigger files (leverages workspace prettier + prettier-plugin-apex).
- 🧹 Command palette action to strip System.debug(...) statements across the active selection or file.
- 🔄 Compare local metadata vs. your org (Monaco diff view for text assets, size checks for binaries).
- 🕸️ “Where is Used” report — scans dependencies across Apex Classes, Flows, and LWC, rendered in a clean interactive tree view.
- 🎨 Unified dark-themed report design — for a consistent visual experience, and interactive search across all HTML reports.
- 🌐 Multilingual reports — HTML/PDF templates honor your VS Code locale or a workspace override (Spanish/English) with per-report language switching.
🧰 Requirements
System
- Node.js 18+ and npm 9+.
- Salesforce CLI (
sf) with Java 11 or newer.
- wkhtmltopdf (for PDF export, Optional, but Recommended).
- Prettier and Prettier-Plugin-Apex.
- An authenticated Salesforce org through the CLI.
- Einstein GPT credentials (Client Id/Secret) if you plan to use AI features.
⚙️ Settings
You’ll find them under Unified Apex Validator in your VS Code settings.
| Setting |
Description |
sfClientId |
Einstein GPT Connected App client id |
sfClientSecret |
Einstein GPT Connected App client secret |
sfDomain |
Salesforce domain (My Domain URL) |
sfRepositoryDir |
Local repo path with your Apex code |
sfCliPath |
Custom Salesforce CLI path (defaults to sf) |
pmdPath |
Optional PMD binary path |
outputDir |
Folder for HTML/PDF reports |
skipIAAnalysis |
Skip Einstein GPT analysis |
sfGptEndpoint |
Einstein GPT API endpoint |
sfGptModel |
GPT model name |
iaPromptTemplate |
Custom AI prompt template |
maxIAClassChars |
Max characters per class sent to GPT |
keepLogFiles |
Keep log files after success |
traceAst |
Enable AST tracing (debug) |
classDocTags |
Required ApexDoc tags for classes |
methodDocTags |
Required ApexDoc tags for methods |
apexDocLanguage |
Language used by the AI ApexDoc generator (spanish or english) |
reportLanguage |
Controls report language: auto (follow VS Code locale), es, or en |
UAV usa automáticamente la org marcada como isDefaultUsername en sf org list --json. Asegúrate de tener una org por defecto conectada (sf org login web) antes de ejecutar el validador.
💡 Dependencies view highlights missing GPT setup fields and disables AI commands until everything’s filled in.
🕹️ How to Use
- Right-click a
package.xml file.
- Select UAV: Validate Apex Code.
- Track progress in the Unified Apex Validator output channel.
- Review reports or logs in the sidebar.
- (Optional) Run UAV: Compare Metadata against Org to diff your local vs. org versions.
- (Optional) Use UAV: Formatear Apex (Allman) from the explorer/editor context menu to apply Allman braces to selected
.cls/.trigger files (requires prettier + prettier-plugin-apex in your workspace).
- (Optional) Use UAV: Where is Used from the editor context menu to run a report that scans dependencies across Apex Classes, Flows, and LWC, showing where each element is referenced.
- (Optional) Use UAV: Remove System.debug Statements from the command palette to clean debug output in the active editor or current selections.
- Available from the explorer and editor context menus for package.xml manifests and supported metadata files (classes, triggers, flows, Lightning bundles, etc.).
- From a manifest, UAV retrieves every type/member declared under ; from a single file it infers the metadata type automatically before running the retrieve.
- Text assets render in the Monaco diff view with syntax highlighting, while binaries surface size differences so you can decide whether to download them.
📝 HTML/PDF reports render in the language defined by UnifiedApexValidator.reportLanguage (default auto). The HTML viewer also exposes a globe selector so teammates can switch between Español and English on demand.
🧭 VS Code Views
📊 Reports
Shows all generated reports (HTML/PDF) with options to refresh, open folder, or view inline in VS Code.
📜 Logs
Lists .log files stored under ~/.uav/logs. Quick buttons to refresh or open the folder.
🔧 Dependencies
Checks Node.js, CLI, Java, wkhtmltopdf, Code Analyzer, and Einstein GPT configuration. Missing ones show in red and can be fixed from here.
🤖 Einstein GPT Setup
- Create an External Connected App with scopes
api and refresh_token.
📘 Helpful docs:
- Assign a user with API Enabled and API Only User permissions.
- Turn on Einstein in Setup → Einstein Generative AI.
- Configure your VS Code settings (
sfClientId, sfClientSecret, sfGptEndpoint, sfGptModel, iaPromptTemplate).
- Authenticate your org via CLI:
sf org login web --alias <alias>
- Refresh the Dependencies view — once all fields are set, AI features will unlock automatically.
🧾 ApexDoc Generation (Beta)
- Command: UAV: Generate ApexDoc.
- Uses Einstein GPT to auto-generate documentation.
- Ensures required tags (
@param, @return, etc.) are filled.
- Disabled when Einstein GPT config is incomplete or
skipIAAnalysis is true.
🧯 Troubleshooting
🧩 Extension not showing
- Make sure the
.vsix is installed or from Marketplace.
- Run Developer: Reload Window.
- Check the Unified Apex Validator output channel.
⚠️ sf or pmd not found
- Run
sf --version and java -version.
- Update PATH or reinstall if needed.
🚫 Default org not connected
- Ejecuta
sf org list --json y verifica que alguna org tenga isDefaultUsername: true.
- Si no existe, ejecuta
sf org login web y marca la org como predeterminada.
- Una vez conectada, vuelve a lanzar el validador.
📄 No reports generated
- The XML must contain
<name>ApexClass</name>.
- Make sure
outputDir exists and is writable.
🤖 AI analysis skipped
- Check
sfClientId, sfClientSecret, sfGptEndpoint, sfGptModel, and iaPromptTemplate.
- Ensure
skipIAAnalysis is false.
🪵 Logs missing
- Install
prettier and prettier-plugin-apex in the workspace that contains your .cls/.trigger files (npm install --save-dev prettier prettier-plugin-apex).
- Refresh the Dependencies view to confirm both are detected (status should display in green).
- Run UAV: Formatear Apex (Allman) again from the explorer/editor context menu.
🗺️ Roadmap
- 🎚️ Configurable log levels
- 💬 Dependency tooltips with detected versions
- 🤖 Deeper Einstein GPT insights per class
- 📦 Markdown and CSV export options
- 🏪 Marketplace release with verified Salesforce badge
👨💻 Author
Created by Oscar Gonzalez
GitHub: @ozkrgonzalez
📄 License
GPL v3 © 2025 – Oscar Gonzalez
| |