Repository navigation
@W-24222796@ Add Compile Status command #977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
WillieRuemmele
merged 10 commits into
salesforcecli:main
from
jamessimone:feature/W-24222796-get-compile-status
Oct 5, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
18176bb
feat: add support for retrieving invalid classes via new tooling API …
jamessimone 7a0518a
feat: pre-PR feedback on command name
jamessimone 68055bb
Merge branch 'salesforcecli:main' into main
jamessimone d1478a5
feat: add compiler warnings to output
jamessimone af84e55
feat: update README
jamessimone 547ee21
fix: code review feedback
jamessimone 0683972
fix: improve table output, clean up stale tests, add NUT
WillieRuemmele 255bca6
chore: remove unused eslint-disable for no-unsafe-return
WillieRuemmele 595850a
fix: restore cli: 'sf' for non-apex commands in NUT
WillieRuemmele 4c42e84
fix: add cli: 'sf' to remaining non-apex NUT commands
WillieRuemmele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # summary | ||
|
|
||
| Fetches the compilation status for Apex classes that are currently invalid or have compilation warnings. | ||
|
|
||
| # description | ||
|
|
||
| Return compile results for only Apex classes and triggers with validation errors or warnings, instead of recompiling the entire org. | ||
|
|
||
| # examples | ||
|
|
||
| - Fetch invalid Apex classes or classes that have compilation warnings for a target org | ||
|
|
||
| <%= config.bin %> <%= command.id %> --target-org me@my.org | ||
|
|
||
| # noResultsFound | ||
|
|
||
| No Apex compiler issues found. | ||
|
|
||
| # minimumApiVersionNotMet | ||
|
|
||
| Apex compile results available in API versions 68.0 and above |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "$ref": "#/definitions/CompilationResult", | ||
| "definitions": { | ||
| "CompilationResult": { | ||
| "type": "object", | ||
| "properties": { | ||
| "status": { | ||
| "type": "string" | ||
| }, | ||
| "results": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/definitions/InvalidApexClassResult" | ||
| } | ||
| } | ||
| }, | ||
| "required": ["status", "results"], | ||
| "additionalProperties": false | ||
| }, | ||
| "InvalidApexClassResult": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string" | ||
| }, | ||
| "namespace": { | ||
| "type": "string" | ||
| }, | ||
| "success": { | ||
| "type": "boolean" | ||
| }, | ||
| "problems": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/definitions/ApexClassProblem" | ||
| } | ||
| }, | ||
| "warnings": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/definitions/ApexClassProblem" | ||
| } | ||
| } | ||
| }, | ||
| "required": ["name", "namespace", "success", "problems", "warnings"], | ||
| "additionalProperties": false | ||
| }, | ||
| "ApexClassProblem": { | ||
| "type": "object", | ||
| "properties": { | ||
| "line": { | ||
| "type": "number" | ||
| }, | ||
| "column": { | ||
| "type": "number" | ||
| }, | ||
| "message": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": ["line", "column", "message"], | ||
| "additionalProperties": false | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright 2026, Salesforce, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| import { | ||
| orgApiVersionFlagWithDeprecations, | ||
| requiredOrgFlagWithDeprecations, | ||
| SfCommand, | ||
| } from '@salesforce/sf-plugins-core'; | ||
| import { Messages, SfError } from '@salesforce/core'; | ||
|
|
||
| Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
| const messages = Messages.loadMessages('@salesforce/plugin-apex', 'get-compile-status'); | ||
|
|
||
| export type ApexClassProblem = { | ||
| line: number; | ||
| column: number; | ||
| message: string; | ||
| }; | ||
|
|
||
| export type InvalidApexClassResult = { | ||
| name: string; | ||
| namespace: string; | ||
| success: boolean; | ||
| problems: ApexClassProblem[]; | ||
| warnings: ApexClassProblem[]; | ||
| }; | ||
|
|
||
| export type CompilationResult = { | ||
| status: string; | ||
| results: InvalidApexClassResult[]; | ||
| }; | ||
|
|
||
| export default class GetCompileStatus extends SfCommand<CompilationResult> { | ||
| public static readonly flags = { | ||
| 'target-org': requiredOrgFlagWithDeprecations, | ||
| 'api-version': orgApiVersionFlagWithDeprecations, | ||
| }; | ||
| public static readonly summary = messages.getMessage('summary'); | ||
| public static readonly description = messages.getMessage('description'); | ||
| public static readonly examples = messages.getMessages('examples'); | ||
|
|
||
| public async run(): Promise<CompilationResult> { | ||
| const { flags } = await this.parse(GetCompileStatus); | ||
| const apiVersion = flags['api-version']; | ||
| if (apiVersion && Number(apiVersion.replace('.0', '')) < 68) { | ||
| throw new SfError(messages.getMessage('minimumApiVersionNotMet')); | ||
| } | ||
|
|
||
| this.spinner.start('Retrieving Apex compilation results'); | ||
|
|
||
| const connection = flags['target-org'].getConnection(apiVersion); | ||
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
| const invalidApexResponse = (await connection.tooling.request({ | ||
| // eslint-disable-next-line no-underscore-dangle | ||
| url: `${connection.tooling._baseUrl()}/apexCompileResults`, | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify({}), | ||
| })) as CompilationResult; | ||
|
|
||
| this.spinner.stop(); | ||
|
|
||
| // the actual command output is only displayed when --json is passed as a flag | ||
| // so we format the results for everyone else | ||
| if (!this.jsonEnabled()) { | ||
| if (invalidApexResponse.results.length > 0) { | ||
| const tableFormatter = (tableItems: ApexClassProblem[]): string => | ||
| tableItems.map((p) => `L${p.line}:C${p.column} - ${p.message}`).join('\n'); | ||
| this.table({ | ||
| columns: ['name', 'namespace', 'success', 'problems', 'warnings'], | ||
| data: invalidApexResponse.results.map((result) => ({ | ||
| ...result, | ||
| problems: tableFormatter(result.problems), | ||
| warnings: tableFormatter(result.warnings), | ||
| })), | ||
| title: 'Compile Status Results:', | ||
| overflow: 'wrap', | ||
| }); | ||
| } else { | ||
| this.log(messages.getMessage('noResultsFound')); | ||
| } | ||
| } | ||
|
|
||
| return invalidApexResponse; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
JSON.stringifyper problem produces output like{"line":10,"column":5,"message":"Unexpected token: }"}in the table cell — not great for human consumption.Consider a readable format, e.g.:
This would render as
L10:C5 - Unexpected token: }which is much easier to scan.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll work a little bit on the output, but I thought the tabled results looked nice as is. Let me play around it with it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried a few different output formats, but the bare string versions just look weird on my terminal. I don't think they're easier to read, and in many cases the "message" would wrap onto a new line in a way that the stringified versions didn't.