Build a Query by Using the SOQL Builder

The Salesforce Object Query Language (SOQL) Query Builder is a part of the Salesforce Extension Pack. This builder helps you build a query by using a form-like visual interface. You can select the components of your query, such as the table, fields, and filters, instead of typing an actual SOQL query. You can instantly view query results, and then save the results to a .csv or a .json file.

Build simple query statements that include:

  • SELECT clause to pick fields from the selected object, or COUNT() to perform an aggregation of the results
  • FROM clause for only one object type
  • WHERE clause to filter your data
  • ORDER BY clause with support for ASC, DESC, NULLS FIRST, and NULLS LAST
  • LIMIT clause

To dig deeper regarding SOQL syntax or to build more complex queries, see the SOQL and Salesforce Object Search Language (SOSL) Reference guide.

To build more complex queries, you can use the text editor.

To build a query by using the SOQL Builder:

  1. Open the Command Palette and type SFDX: Create Query in SOQL Builder.

    Select the SFDX: Create Query in SOQL Builder command in the Command Palette

  2. Enter a name for the query.

  3. Select the default directory or specify a directory where the query is stored, and press Enter.

  4. In the SOQL Builder, use the UI elements to indicate various parts of your query. In this example, from Account, Id, BillingCountry, and Name details show for companies with more than 100 employees. The actual SOQL query appears in the SOQL Query box.

    SOQL Query Builder with Accounts query

  5. Select an object from the From dropdown list.

  6. Select one or more fields to show.

  7. Add one or more filter conditions for the WHERE clause.

    To add a filter, select a field and an operator, and specify a value. To add another filter condition, click ADD and select AND or OR operator. The filters are added in the format WHERE FIELD_NAME OPERATOR VALUE [AND/OR FIELD_NAME OPERATOR VALUE].

    For example, WHERE NumberOfEmployees > 100 OR Name LIKE 'A%'.

  8. To sort the results, select a field as the ORDER BY clause. Specify the order of sorting and how NULL results are shown.

  9. Specify the number of records to limit the results to.

To open the query in a text editor, click Toggle button to open the query in a text editor.

  • The .soql files containing the queries are saved in the <project-folder>/scripts/soql directory.
  • The .csv and .json files with your query results are stored under the <project-folder>/.sfdx/data directory.

Explorer view with CSV and SOQL files

To open an existing file in the text editor, click the file in the explorer or drag the file onto the editor. To open the query in the SOQL Builder, click Toggle button to open the query in a text editor.