Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
All tools

Apex & SOQL Formatter

Re-indent Apex by curly-brace depth, or pretty-print a standalone SOQL query. Auto-detects which one you pasted.

Apex or SOQL

Formatted

Output appears here.

Related dictionary terms

§

About this tool

Paste an Apex class, trigger, or anonymous block and this tool re-indents it by curly-brace depth, with an optional uppercase-keywords toggle. Paste a standalone SOQL query and it pretty-prints each clause on its own line with subqueries indented one level deeper. The tool sniffs the input and routes to the right formatter, so you don't have to pick a mode.

How it works

On every keystroke the tool checks whether the input looks like a SOQL query (trimmed text starts with SELECT or FIND, no class/trigger/interface keyword, no top-level curly braces). SOQL input goes through the SOQL formatter: tokenise keeping string literals and bind variables intact, then re-emit with each clause - SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET, FOR UPDATE - on its own line. Apex input goes through the Apex formatter: tokenise keeping strings, comments, and embedded `[ SELECT ... ]` blocks intact, then walk line by line incrementing indent on `{` and decrementing before `}`. The uppercase-keywords toggle and indent size apply to both modes.

When to use it
  • Cleaning up Apex copied from a debug log or someone else's Slack message.
  • Pretty-printing a one-line SOQL query pulled from a log before pasting it into a code review.
  • Normalising a class's indentation before committing - useful when teams contribute from a mix of editors.
  • Quick formatting before posting an Apex snippet or SOQL query into a code review when you can't reach for a full IDE.
§

Frequently asked questions

How does the tool decide between Apex and SOQL mode?
It looks at the trimmed input. If it starts with SELECT or FIND, has no class/trigger/interface keyword, and no top-level curly braces, it formats as SOQL. Anything else is treated as Apex.
Does this replace the Prettier Apex plugin?
No. It's a quick-and-dirty in-browser re-indenter. For full formatting in your IDE - wrap-at-column, comma alignment, etc. - install Prettier with the Apex plugin or use the Salesforce Code Builder formatter.
What about SOQL embedded inside Apex?
SOQL inside `[ ... ]` blocks is preserved as-is when the input is Apex. Copy the SOQL out into a fresh paste if you want it pretty-printed on its own.
Does it work on triggers?
Yes - triggers, classes, anonymous Apex blocks, and test methods all format the same way (curly-brace depth).