Skip to content

fix: support :bind in SOSL WITH DIVISION clause#89

Merged
nawforce merged 3 commits into
mainfrom
fix/issue-44-sosl-soql-binds
Apr 23, 2026
Merged

fix: support :bind in SOSL WITH DIVISION clause#89
nawforce merged 3 commits into
mainfrom
fix/issue-44-sosl-soql-binds

Conversation

@kjonescertinia

@kjonescertinia kjonescertinia commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Partially fixes #44. Extends soslWithClause so WITH DIVISION accepts StringLiteral | boundExpression, allowing:

List<List<SObject>> r = [FIND :q IN ALL FIELDS RETURNING Account
    WITH DIVISION = :myDivision LIMIT :myLimit];

This is the only part of #44 that corresponds to a real parser gap. See the discussion below for why the rest was dropped.

Why not the other reported cases?

The #44 report included two examples transcribed from the Salesforce Apex Developer Guide. Both were tested against a real Apex org using sf apex run:

  1. SOQL WHERE :A.TYPE INCLUDES (...) — bind on LHS of WHERE. Apex compiler rejects it inline (Unexpected token ':') and via Database.queryWithBinds (System.QueryException: unexpected token: ':'). Semantically it would reduce to a comparison between two constants, so it's unlikely to be intended behaviour. Bind on the RHS (INCLUDES (:c)) was already handled by the existing value rule — no change needed.

  2. SOSL WITH DIVISION = :bind — accepted by Apex. This is the change in this PR.

  3. SOSL WITH NETWORK|PRICEBOOKID|METADATA = :bind — all three rejected by the Apex compiler. Literal-only.

Keeping the grammar aligned with the Apex compiler rather than with the (evidently flawed) docs example, consistent with prior corrections like 3.1.0's modulus removal and 3.5.0's do-while tightening.

Test plan

  • npm test — 75/75 (74 baseline + 1 new testBindVarInDivisionClause)
  • mvn test — 74/74 (73 baseline + 1 matching Java test)
  • npm run lint clean
  • Verified against pre-release org via sf apex run: WITH DIVISION = :bind compiles; all other reported variants are rejected by the Apex compiler

…SL WITH clauses

Two related grammar gaps around `:expr` bind variables:

1. `fieldExpression` only accepted `fieldName` or `soqlFunction` as the
   left operand. Salesforce permits a bind expression too, e.g.
   `WHERE :A.TYPE INCLUDES ('Customer - Direct')`. Added
   `boundExpression` as a third alternative.

2. `soslWithClause` hard-coded `StringLiteral` for `WITH DIVISION`,
   `WITH NETWORK`, `WITH PRICEBOOKID`, and `WITH METADATA`. Each now
   accepts `StringLiteral | boundExpression` so bind variables can be
   used, e.g. `WITH DIVISION = :myString`.

Both cases are documented in the Salesforce "SOQL and SOSL Apex
Variables" guide.

Fixes #44
Tested each of the originally-reported grammar extensions against a
real Apex org via `sf apex run`:

- SOQL `:bind` on the LHS of a WHERE comparison (e.g. `:A.TYPE INCLUDES (...)`):
  Apex compiler rejects it, both inline and via `Database.queryWithBinds`
  (`System.QueryException: unexpected token: ':'`). The example in the
  Salesforce Apex Developer Guide appears to be a non-working snippet
  (semantically it would reduce to a comparison between two constants).
  Binds on the RHS inside value lists already parse today via the
  existing `value` rule — no change needed.

- SOSL `WITH NETWORK|PRICEBOOKID|METADATA = :bind`: all three rejected
  by the Apex compiler. Only literal StringLiteral is accepted.

- SOSL `WITH DIVISION = :bind`: accepted by the Apex compiler
  (documented, verified).

Keeping only the DIVISION change so the grammar stays aligned with what
the Apex compiler actually accepts, consistent with prior corrections
(e.g. 3.1.0 modulus removal, 3.5.0 do-while tightening).
@kjonescertinia kjonescertinia changed the title fix: support Apex bind variables in SOQL INCLUDES LHS and SOSL WITH clauses fix: support :bind in SOSL WITH DIVISION clause Apr 22, 2026
@kjonescertinia kjonescertinia requested a review from nawforce April 22, 2026 22:18
@nawforce

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nawforce nawforce merged commit fe4b87a into main Apr 23, 2026
@nawforce nawforce deleted the fix/issue-44-sosl-soql-binds branch April 23, 2026 14:26
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.

Parse error with SOSL binding vars

2 participants