Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Apex code

Apex Formatter

Re-indent Apex by curly-brace depth and (optionally) uppercase keywords. Quick clean-up for code copied out of dev console.

Apex

Formatted

Output appears here.

Related dictionary terms

§

About this tool

The Salesforce Developer Console doesn't carry indentation hints when you copy code into another window, and Quick Actions / Formula Editor outputs are notoriously messy. This formatter re-indents any Apex snippet by curly-brace depth - 4 spaces per level by default - and gives you a one-click "uppercase keywords" toggle for teams that prefer the SQL-style convention.

How it works

The formatter tokenises the input keeping string literals, comments, and SOQL inline blocks (`[ SELECT ... ]`) intact. It then walks each line, increments the indent on `{` and decrements before `}`, and writes the result with consistent spacing. The uppercase-keywords toggle uppercases the Apex reserved word set without touching identifier names, string content, or method calls.

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

Frequently asked questions

Does this replace the Prettier Apex plugin?
No. It's a quick-and-dirty re-indenter for in-browser use. 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 embedded SOQL?
SOQL inside `[ ... ]` is preserved as-is. Use the SOQL Formatter tool first if you need the SOQL itself pretty-printed.
Does it work on triggers?
Yes - triggers, classes, anonymous Apex blocks, and test methods all format the same way (curly-brace depth).