Salesforce SOQL Parser for Java
General SQL Parser (GSP) parses Salesforce SOQL with a dedicated, hand-tuned grammar — full AST access, offline syntax validation, formatting, and rewriting. One commercial SDK — Salesforce SOQL is available in the Java edition.
Salesforce SOQL queries that GSP parses
SELECT Account.Name, COUNT(Id)
FROM Contact
WHERE CreatedDate = THIS_YEAR
GROUP BY Account.Name
HAVING COUNT(Id) > 5; Parse it in Java
import gudusoft.gsqlparser.*;
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvsoql);
parser.sqltext = sql; // the Salesforce SOQL query above
if (parser.parse() == 0) {
System.out.println(parser.sqlstatements.size() + " statement(s) parsed");
} else {
System.out.println(parser.getErrormessage());
} Java edition only. The .NET library has no Salesforce SOQL grammar, so this dialect cannot be parsed from C# or VB.NET. See the .NET SQL Parser SDK for the dialects it does cover.
What GSP handles in Salesforce SOQL
- Parent-to-child and child-to-parent relationship queries
- TYPEOF polymorphic field selection
- GROUP BY ROLLUP and CUBE with GROUPING()
- Relative date literals such as LAST_N_DAYS:n
- USING SCOPE and WITH DATA CATEGORY filters
- sObject-targeted SELECT queries
- Offline validation of SOQL embedded in Apex code
Beyond parsing, the same AST powers table/column extraction, validation, formatting, and rewriting for Salesforce SOQL.
Salesforce SOQL resources
- Salesforce SOQL syntax reference — dialect documentation
- Salesforce SOQL keyword compatibility — every keyword, and whether it can be an identifier
- Salesforce SOQL capability data (JSON) — measured construct-by-construct parse coverage, machine-readable
- Java quick start — Maven/Gradle setup and first parse
Common questions
Do I need a live Salesforce SOQL connection to validate queries?
No. GSP validates Salesforce SOQL syntax completely offline. You get error line and column positions, the offending token, and a hint — with no server, driver, or credentials involved.
How complete is the Salesforce SOQL grammar?
GSP uses a dedicated hand-tuned grammar for Salesforce SOQL — not a generic SQL grammar with flags. The parser recognizes 541 Salesforce SOQL keywords and knows which 500 of them can also be used as identifiers, which is exactly the kind of edge case that breaks generic parsers.
Can I use the Salesforce SOQL parser from C# / .NET?
Not currently. Salesforce SOQL is a Java-edition dialect — the .NET library ships 15 dedicated grammars and Salesforce SOQL is not one of them, so there is no C# code path for it. Everything else on this page describes the Java SDK. If you need Salesforce SOQL in .NET, email info@sqlparser.com; customer demand is how dialects get prioritized for the .NET port.