Skip to content

feat: add --debug-level and --category-level flags to apex run @W-18404446@ - #967

Open
WillieRuemmele wants to merge 5 commits into
mainfrom
wr/debugLevelFlags
Open

WillieRuemmele wants to merge 5 commits into
mainfrom
wr/debugLevelFlags

Conversation

@WillieRuemmele

Copy link
Copy Markdown
Contributor

Summary

  • Add --debug-level flag to sf apex run (options: NONE, DEBUGONLY, DB, PROFILING, CALLOUT, DETAIL)
  • Add --category-level flag for fine-grained per-category control (format: Category=Level, repeatable)
  • Flags are mutually exclusive; validates category names and level values
  • Input validation with clear error messages for invalid categories/levels

Dependency

Library PR: forcedotcom/salesforcedx-apex#684
This PR requires the @salesforce/apex-node release from the above PR. After that merges and publishes, bump @salesforce/apex-node in package.json to the new version and the CI build will pass.

How to verify

Unit tests (with local library link)

yarn add @salesforce/apex-node@file:../salesforcedx-apex
npx nyc mocha "test/**/*.test.ts"
yarn add @salesforce/apex-node@^9.0.0  # restore

Manual (after library publishes)

# Default behavior (unchanged)
sf apex run -f test.apex

# Set a predefined debug level
sf apex run -f test.apex --debug-level DETAIL

# Set individual category levels
sf apex run -f test.apex --category-level Apex_code=FINEST --category-level Db=FINE

# Verify mutual exclusivity
sf apex run -f test.apex --debug-level DETAIL --category-level Apex_code=FINEST
# ^ should error

# Verify validation
sf apex run -f test.apex --category-level BadCategory=FINEST
# ^ should error with valid category names

@W-18404446@

Test plan

  • Existing tests pass unchanged (default behavior preserved)
  • --debug-level DETAIL passes debugLevel to executeAnonymous
  • --category-level Apex_code=FINEST --category-level Db=FINE passes structured debugCategories
  • Invalid format, invalid category, invalid level all throw clear errors
  • Manual: verify flag descriptions appear in sf apex run --help
  • Manual: verify log output changes with DETAIL vs default on a real org

…04446@

Allow users to control the debug log verbosity when executing anonymous Apex.
--debug-level sets a predefined SOAP log type (NONE, DEBUGONLY, DB, PROFILING,
CALLOUT, DETAIL). --category-level sets individual category levels for
fine-grained control (e.g., Apex_code=FINEST, Db=FINE).
@WillieRuemmele
WillieRuemmele requested a review from a team as a code owner September 4, 2026 19:39
- Use indexOf('=') for robust key=value parsing (handles extra = segments)
- Trim whitespace from parsed category and level values
- Deduplicate category-level entries (last-wins when same category repeated)
- Add CLI examples for --debug-level and --category-level flags
- Add test for duplicate category deduplication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants