Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Data & queries

SOQL Formatter

Pretty-print SOQL: line-break before each clause, indent subqueries, optionally uppercase keywords.

SOQL

Formatted

Output appears here.

Related dictionary terms

§

About this tool

SOQL written inside Apex strings or copy-pasted from logs is usually one long line - fine for the runtime, painful to read in code review. This formatter takes any SOQL query (single-line or multi-line) and re-emits it with each clause on its own line, subqueries indented one level deeper, and keywords either left as-is or uppercased to match your team's style.

How it works

The formatter tokenises the input keeping string literals and bind variables intact, then re-emits with clause-aware indentation. SELECT, FROM, WHERE, WITH, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET, FOR UPDATE, and FOR VIEW each get their own line. Subqueries inside SELECT or WHERE clauses indent recursively. The uppercase-keywords toggle only affects reserved words; it never touches field or object API names.

When to use it
  • Formatting SOQL pulled from a debug log into something pasteable into a code review or Slack thread.
  • Cleaning up a one-line SOQL string in a controller before extracting it to a constant.
  • Comparing two near-identical queries side-by-side to spot the differing clause.
  • Teaching SOQL - the formatted output makes the clause structure obvious to a reader who is new to the language.
§

Frequently asked questions

Does the formatter validate that my SOQL is correct?
No - it formats syntactically valid SOQL. If you paste an incomplete query or one with a typo, the formatter still re-indents it; you'll get an error from Salesforce when you run it.
Are bind variables safe?
Yes. `:variableName` and `:Map['key']` patterns are treated as a single token and kept verbatim.
Does it handle nested aggregate functions?
Yes - COUNT, SUM, AVG, MIN, MAX, and COUNT_DISTINCT keep their parentheses intact and are not broken across lines.