ApexGuru Engine
ApexGuru is an AI-driven performance and code optimization engine integrated into Salesforce Code Analyzer. It works alongside the PMD, ESLint, and RetireJS engines to detect SOQL inefficiencies and scalability issues in your Apex code. ApexGuru executes real-time scans on connected Salesforce orgs directly through the Salesforce CLI and delivers exact line-level highlights, severity ratings, and actionable recommendations as JSON output.
Code Analyzer determines its scanning mode automatically based on your org’s ApexGuru settings:
-
Advanced Mode: Scans runtime code when your org or its parent org family has enabled the ApexGuru engine through the Salesforce UI Setup page.
-
Basic Mode: Performs standard static code analysis on the connected org when neither your org nor its parent org family has enabled ApexGuru.
Note: Scan modes are non-configurable at trigger time via the CLI or configuration files.They are automatically determined based on your org’s ApexGuru settings. Org eligibility and hierarchy determine whether Code Analyzer uses Advanced or Basic Mode. For details on how inheritance works across different environments, see these FAQs on ApexGuru.
Run a Scan via Salesforce CLI
Use the sf code-analyzer run --rule-selector apexguru command to run a scan with the ApexGuru engine. Specify the target org and output preferences. You must be connected to the target org. Authentication to the target org is through Salesforce CLI and not the configuration file. There’s no username, password, or token property. The engine reuses your sf login session.
When the execution completes, Salesforce Code Analyzer prints a summary of findings to the console.
View the JSON Results
ApexGuru returns detailed JSON output for each violation, including location, issue description, severity, and suggested fixes.
ApexGuru scans .cls and .trigger files. ApexGuru doesn’t scan metadata XML, objects, flows, and other file types.
Integrate with CI/CD
ApexGuru scans a connected Salesforce org rather than local files, you must authenticate your org before you run the scan using ApexGuru engine.
Authenticate to your target org. Use either the JSON Web Token Bearer Flow or an SFDX Auth URL. See Authenticate a Salesforce Org in CI/CD for setup steps for both methods.
If you use GitHub Actions, add these steps to your workflow after the authentication step to run ApexGuru through the `run-code-analyzer` GitHub Action.
See CI/CD Integration for general Code Analyzer CI/CD guidance that also applies to ApexGuru scans, such as writing results to an output file and using severity thresholds.
Integrate with VS Code
To get ApexGuru scan results directly in your development workspace, set the Code Analyzer Rule Selectors to apexguru in your extension settings. Then when you right-click a file in the Explorer or save an active Apex file, ApexGuru scans your code.
In the editor, lines containing ApexGuru violations are highlighted. Hover over a line to inspect combined engine findings. For example, view PMD rules alongside ApexGuru performance warnings.
As you edit and save the class file, ApexGuru updates the line numbers dynamically.
To customize the ApexGuru engine, add these settings to your code-analyzer.yml file.
| Property | Type | Default | Constraints | Purpose |
|---|---|---|---|---|
disable_engine | boolean | false | — | Turns off the ApexGuru engine. To speed up Code Analyzer output and disable ApexGuru, turn off the engine in your configuration. |
target_org | string | (none → default org) | Must resolve to an authenticated org | The Salesforce org to run the remote scan against. |
api_timeout_ms | number (ms) | 300000 (5 min) | > 0 | Time limit on the scan: submit, poll, and decode. The api_* settings never override api_timeout_ms, even if you tune polling. The scan always stops at the overall timeout budget. |
api_initial_retry_ms | number (ms) | 2000 (2 sec) | > 0 | Delay before the first poll for results. |
api_max_retry_ms | number (ms) | 60000 (60 sec) | > 0 and >= api_initial_retry_ms | Upper limit on the delay between polls. |
api_backoff_multiplier | number | 2 | >= 1 | How fast the poll delay grows after each round. |
To modify rule settings, see Customize the Configuration.
To prevent system overload and maintain scan performance, Code Analyzer enforces scan request limits at the user, org, and org family levels.
| Limit Type | Threshold | Scope & Behavior |
|---|---|---|
| Per User (Short Burst) | 3 scans / 60 seconds | Enforced per individual Salesforce user account. |
| Per Org (Short Burst) | 5 scans / 60 seconds | Combined aggregate limit across all users scanning the same requesting org. |
| Per Org (Daily Quota) | 100 scans / 24 hours | Total daily limit allowed for a single requesting org. |
| Per Resolved Org (Daily Quota) | 200 scans / 24 hours | Shared quota applied at the parent Production/Full Copy org level after org resolution |