SOQL to Apex Query Converter
Turn a SOQL query into ready-to-paste Apex: an inline [SELECT ...] assignment, or a Database.query() call with the string safely escaped.
SOQL
Apex
Output appears here.Turn a SOQL query into ready-to-paste Apex: an inline [SELECT ...] assignment, or a Database.query() call with the string safely escaped.
Output appears here.You have a SOQL query that runs in the Developer Console or Workbench, and now you need it inside an Apex class. This tool wraps the query as Apex for you: either an inline static query assigned to a typed List, or a dynamic Database.query() call with the query string correctly escaped. Name the variable, pick the style, and copy the result straight into your class.
For the inline form the tool emits a List assignment using the bracketed [SELECT ...] syntax that Apex compiles natively, naming the variable whatever you choose. For the dynamic form it wraps the query in Database.query() and escapes single quotes in the SOQL so the resulting Apex string literal is valid. It does not infer the concrete sObject type for the dynamic form, since Database.query returns a generic List, so you cast as needed. Conversion happens locally on each keystroke.