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.

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.

1sf code-analyzer run \
2  --rule-selector apexguru \
3  --include-suggestions \
4  --output-file /tmp/apexguru.json \
5  --target-org <my-org-alias>

When the execution completes, Salesforce Code Analyzer prints a summary of findings to the console.

1Summary
2  Found 68 violation(s) across 61 file(s).
3  1 High Severity violation(s) found.
4  58 Moderate Severity violation(s) found.
5  9 Low Severity violation(s) found.
6
7Additional Log Information written to:
8  /tmp/apexguru.json

View the JSON Results

ApexGuru returns detailed JSON output for each violation, including location, issue description, severity, and suggested fixes.

1{
2  "engine": "apexguru",
3  "fileName": "force-app/main/default/classes/CRL_TEST_VALIDATE_ROLLUPS.cls",
4  "violations": [
5    {
6      "ruleName": "AvoidSchemaGetObjectDescribeInApex",
7      "severity": 3,
8      "category": "Performance",
9      "message": "Avoid using Schema.getGlobalDescribe() in Apex. This method causes unnecessary overhead, decreases performance, and increases latency.",
10      "locations": [
11        {
12          "startLine": 412,
13          "startColumn": 8
14        }
15      ],
16      "primaryLocationIndex": 0,
17      "resources": [
18        "https://developer.salesforce.com/site-resources/apexguru-rules#schema_getdescribe_not_efficient"
19      ],
20      "suggestions": [
21        "Use Schema.getGlobalDescribe().get('ObjectName') or direct object tokens instead."
22      ],
23      "tags": [
24        "Recommended",
25        "Performance",
26        "Apex"
27      ]
28    }
29  ]
30}

ApexGuru scans .cls and .trigger files. ApexGuru doesn’t scan metadata XML, objects, flows, and other file types.

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.

ApexGuru Configuration Reference 

To customize the ApexGuru engine, add these settings to your code-analyzer.yml file.

PropertyTypeDefaultConstraintsPurpose
disable_enginebooleanfalseTurns off the ApexGuru engine. To speed up Code Analyzer output and disable ApexGuru, turn off the engine in your configuration.
target_orgstring(none → default org)Must resolve to an authenticated orgThe Salesforce org to run the remote scan against.
api_timeout_msnumber (ms)300000 (5 min)> 0Time 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_msnumber (ms)2000 (2 sec)> 0Delay before the first poll for results.
api_max_retry_msnumber (ms)60000 (60 sec)> 0 and >= api_initial_retry_msUpper limit on the delay between polls.
api_backoff_multipliernumber2>= 1How fast the poll delay grows after each round.

Limitations 

  • 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.
  • ApexGuru scans .cls and .trigger files. ApexGuru doesn’t scan metadata XML, objects, flows, and other file types.
  • The api_* settings never override api_timeout_ms, even if you tune polling. The scan always stops at the overall timeout budget.

To modify rule settings, see Customize the Configuration.

See Also