About SOQL Formatter

Format Salesforce Object Query Language (SOQL) queries with proper indentation, keyword highlighting, and support for subqueries.

Features

  • Re-indents single-line SOQL with keyword highlighting
  • Handles parent-to-child subqueries and nested SELECTs
  • Preserves relationship (dot-notation and __r) field paths
  • Formats WHERE, GROUP BY, ORDER BY, and LIMIT clauses
  • 100% client-side — your queries never leave your browser

Pro Tips

  • Paste a query straight from the Developer Console or debug logs to make it readable
  • Format before code review so relationship traversals are easy to scan
  • Use the SOQL Query Builder first if you are unsure of field or relationship names
  • Keep filters on indexed fields (Id, Name, external IDs) to stay selective
  • Bulkify: never run a formatted query inside an Apex loop — query once into a collection

Reference

SOQL vs SQL — key differences

  • No SELECT * — every field must be named explicitly
  • No JOIN — relationships are traversed with dot notation or subqueries
  • Read-only — INSERT/UPDATE/DELETE are separate DML, not SOQL
  • Runs inside multi-tenant governor limits (query and row caps)
  • Adds date literals (TODAY, LAST_N_DAYS:30) and semi-joins (IN (SELECT …))

Before and after formatting

  • Before: SELECT Id,Name,(SELECT LastName FROM Contacts) FROM Account WHERE CreatedDate>LAST_N_DAYS:30 ORDER BY Name LIMIT 200
  • After: SELECT keyword, each field, the nested subquery, WHERE, ORDER BY, and LIMIT each land on their own indented lines for readability

Governor limits that shape queries

  • 100 SOQL queries per synchronous transaction (200 asynchronous)
  • 50,000 records retrieved by SOQL per transaction
  • LIMIT caps at 50,000 rows; OFFSET caps at 2,000 rows
  • Non-selective filters on large objects throw a query error — index your WHERE

Relationship queries

  • Child-to-parent (up to 5 levels): SELECT Name, Account.Owner.Name FROM Contact
  • Parent-to-child subquery: SELECT Name, (SELECT LastName FROM Contacts) FROM Account
  • Custom relationships use the __r suffix (e.g. Invoices__r)
  • Up to 20 parent-to-child subqueries per statement

Frequently Asked Questions

What is SOQL?

SOQL (Salesforce Object Query Language) is a query language for Salesforce data. It is similar to SQL but designed for Salesforce's object-based data model.

Does this validate my SOQL?

This tool formats SOQL for readability but does not validate it against a Salesforce org. Use Developer Console or Workbench for validation.

How is SOQL different from SQL?

SOQL queries the Salesforce object model rather than raw tables. It has no SELECT *, no JOIN keyword (relationships are traversed with dot notation or subqueries), and is read-only — inserts, updates, and deletes are handled by separate DML statements. It also runs inside multi-tenant governor limits and adds Salesforce-specific features like date literals and relationship queries.

Can this formatter handle subqueries and relationship fields?

Yes. Parent-to-child subqueries (SELECT Name, (SELECT LastName FROM Contacts) FROM Account) and child-to-parent dot-notation paths (Account.Owner.Name) are preserved and indented so the structure is easy to read. Custom relationship names with the __r suffix are kept intact.

Does formatting change what my query returns?

No. Formatting only adds whitespace and line breaks for readability — the fields, filters, ordering, and limits are unchanged. The query returns exactly the same records before and after formatting.

Why does my SOQL hit a governor limit?

Common causes are querying inside a loop instead of bulkifying, retrieving more than 50,000 records in a transaction, or a non-selective WHERE clause on a large object. Keep filters on indexed fields (Id, Name, external IDs, lookups) and query once into a collection rather than per-record.