Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Data & SOQL

SOQL Query Formatter

Pretty-print a SOQL query with each clause on its own line and subqueries indented, with optional uppercase keywords and a 2- or 4-space indent.

SOQL

Formatted

Output appears here.

Related dictionary terms

§

About this tool

A one-line SOQL query is fine until it grows a handful of fields, a couple of subqueries, and a long WHERE clause, at which point it becomes hard to read in a code review or a log. This formatter takes a SOQL query and rewrites it with each major clause on its own line, subqueries indented one level deeper, and keywords optionally uppercased, so the structure of the query is obvious at a glance. String literals and bind variables are preserved exactly.

How it works

The formatter tokenises the query while keeping quoted string literals and bind expressions intact, then re-emits it clause by clause: SELECT, FROM, WHERE, WITH, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET, and FOR UPDATE each start a new line. Parenthesised subqueries in the SELECT list are formatted recursively and indented one level deeper than their parent. The uppercase-keywords toggle normalises clause and operator keywords without touching field or object names, and the indent control switches between two and four spaces. Formatting runs locally on each keystroke.

When to use it
  • Cleaning up a dense SOQL query pulled from a debug log before pasting it into a pull request or a ticket.
  • Making a query with nested relationship subqueries readable so a reviewer can follow the parent-to-child structure.
  • Normalising query style across a team so diffs show real logic changes rather than whitespace.
§

Frequently asked questions

Will it change my field or object names?
No. Only clause and operator keywords are uppercased when you enable that toggle. Field names, object names, string literals, and bind variables are preserved exactly as you typed them.
Does it validate the query?
It formats rather than validates. It will lay out a syntactically odd query as best it can, but it does not check field-level security, object existence, or whether the query would actually run in your org.
How are subqueries handled?
Relationship subqueries inside the SELECT list are formatted recursively and indented one level deeper than the outer query, so the parent-to-child nesting stays visually clear.