Skip to content

Add Formula Exception Stubs to System Namespace - #78

Merged
kjonescertinia merged 2 commits into
mainfrom
issue-77-formula-exceptions
Jul 26, 2026
Merged

Add Formula Exception Stubs to System Namespace#78
kjonescertinia merged 2 commits into
mainfrom
issue-77-formula-exceptions

Conversation

@tmitchellcertinia

Copy link
Copy Markdown
Collaborator

Summary

This PR adds FormulaEvaluationException and FormulaValidationException to the System package so apex-ls resolves the exceptions the FormulaEval API throws, instead of reporting "No type declaration found". Closes #77.

Both follow the standard exception-stub pattern (extends Exception, four universal constructors, bodies throwing UnsupportedOperationException), matching MathException.

Salesforce Documentation

These exceptions are real but oddly undocumented, they appear only in prose and only in the original preview note:

NOTE: No // [doc link] comment on either class since no reference page exists to point at.

Testing/Evidence

Run the following Apex snippet against an org on API version 67.0:

// Reference the types explicitly so the compiler must resolve them under System.
System.Type validationType = System.FormulaValidationException.class;
System.Type evaluationType = System.FormulaEvaluationException.class;
System.debug('Resolved type (validation): ' + validationType.getName());
System.debug('Resolved type (evaluation): ' + evaluationType.getName());

// FormulaValidationException — thrown at build() time by an invalid formula.
try {
    Formula.builder()
        .withType(Account.SObjectType)
        .withReturnType(FormulaEval.FormulaReturnType.Decimal)
        .withFormula('NOT_A_FUNCTION(1)')
        .build()
        .evaluate(new Account());
} catch (System.FormulaValidationException fe) {
    System.debug('Caught System.FormulaValidationException: ' + fe.getMessage());
}

// FormulaEvaluationException — thrown at evaluate() time (division by zero).
try {
    Formula.builder()
        .withType(Account.SObjectType)
        .withReturnType(FormulaEval.FormulaReturnType.Decimal)
        .withFormula('1 / 0')
        .build()
        .evaluate(new Account());
} catch (System.FormulaEvaluationException fee) {
    System.debug('Caught System.FormulaEvaluationException: ' + fee.getMessage());
}
Screenshot 2026-07-23 at 17 10 59

Additional Changes

  • .github/copilot-instructions.md tweaks: "current calendar year" instead of hardcoded 2025, v64/Summer '25 bumped to v67/Summer '26, native-type allowlist spelled out, full header example
  • Ensure that Claude picks up the project instructions by adding a new .claude/CLAUDE.md which just references .github/copilot-instructions.md

tmitchellcertinia and others added 2 commits July 23, 2026 14:42
Fix stale/inaccurate guidance in copilot-instructions.md: show the BSD
copyright header in the stub pattern, drop the hardcoded 2025 year in
favour of the current year, permit native Exception/UnsupportedOperationException
in the import rule, and bump the version example to v67.X.X (Summer '26).

Add .claude/CLAUDE.md that forwards to copilot-instructions.md so Claude
Code and Copilot share one source of instructions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add FormulaValidationException and FormulaEvaluationException to the
System namespace so apex-ls resolves the exceptions thrown by the
Formula/FormulaEval API instead of reporting "No type declaration found".

Closes #77

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kjonescertinia
kjonescertinia merged commit cddc129 into main Jul 26, 2026
1 check passed
@kjonescertinia
kjonescertinia deleted the issue-77-formula-exceptions branch July 26, 2026 14:07
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.

Missing System exceptions: FormulaValidationException and FormulaEvaluationException

2 participants