---
schema_version: "1"
id: ae8d039771838e6b3ffd696433103705fb31398e2644a26916796e75a7da497c
title: SELECT
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-soql-sosl/guides/soql-sosl/sforce-api-calls-soql-select-fields.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-soql-sosl/guide/sforce-api-calls-soql-select-fields.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8212f0a9169d32056e9ea386e1fd7f8cbeeaa26bb6dab2622c13f0a28006a2f9
products:
  - SOQL and SOSL Reference
  - Platform Developer Content
---

# SELECT

SOQL query syntax consists of a required `SELECT` statement that specifies the fields to query. The `fieldList` in the `SELECT` statement specifies the list of one or more fields, separated by commas, that you want to retrieve.

```soql
SELECT fieldList [subquery][...]
```

Use the `FIELDS()` keyword in the `fieldList` to select groups of fields without knowing their names in advance. This keyword simplifies SELECT statements, avoids the need for multiple API calls, and provides a low-code method to explore the data in your org. This keyword is available in API version 51.0 and later.

Using a field list in a SOQL SELECT statement (for example, `SELECT Id, Name FROM Account`) can be complicated if you need to retrieve many fields. And if you don’t know what fields an object has, you must first get a description of the object. Typically, you use a call to first get a description of the object, then parse the description to identify the fields. Then you construct a SOQL query that specifies the fields, and then make another call to submit the query.

To simplify this process, the `FIELDS()` keyword lets you select fields easily, without knowing their names in advance. The `FIELDS()` keyword eliminates the need for a round trip to the server to prepare a SOQL statement, simplifies query statements, and makes it much easier to explore the shape of your objects. It also helps avoid exceeding the character limits on SOQL queries and the URI length limit for REST calls.

You can include any of these in the field list:

- `FIELDS(ALL)`—select all the fields of an object.
- `FIELDS(CUSTOM)`—select all the custom fields of an object.
- `FIELDS(STANDARD)`—select all the standard fields of an object.

In each case, `FIELDS()` respects field-level security so it only shows the fields that you have permission to access.

## Usage

You can use `FIELDS()` as the complete field list. For example:

- `SELECT FIELDS(ALL) FROM Account LIMIT 200`
- `SELECT FIELDS(CUSTOM) FROM Account LIMIT 200`
- `SELECT FIELDS(STANDARD) FROM Account`

You can also use `FIELDS()` with other field names in the field list. For example:

- `SELECT Name, Id, FIELDS(CUSTOM) FROM Account LIMIT 200`
- `SELECT someCustomField__c, FIELDS(STANDARD) FROM Account`

The `FIELDS()` keyword can also be used in subqueries. For example:

```soql
SELECT
   Account.Name,
   (SELECT FIELDS(ALL) FROM Account.Contacts LIMIT 200)
FROM Account
```

The API returns an error if the `SELECT` statement results in any duplicated field names. For example, this query:

```soql
SELECT Id, FIELDS(ALL) FROM User LIMIT 200
```

gives this error:

```soql
HTTP/1.1 400 Bad Request
[
   {
      "message" : "duplicate field selected: Id",
      "errorCode" : "INVALID_FIELD"
   }
]
```

## Support for FIELDS()

The `FIELDS()` keyword is supported in these platform features.

- Apex
- The SOQL language wherever query or queryAll operations can be executed.
- Query jobs in Bulk API 2.0.
- The Salesforce CLI.
- The /query and /queryAll resources in the Lightning Platform REST API.
- The query() and queryAll() operations in the Lightning Platform SOAP API.

When building SOAP API integrations, take care when adopting `FIELDS()` with grouping options `STANDARD`, `CUSTOM`, and `ALL`.Any change to an org’s object model (such as admin modification, feature enablement, or update via major release) must be immediately reflected in the enterprise WSDL. Otherwise, an error is thrown as the query operation returns a result that doesn’t match the contract with the client.

## Bounded and Unbounded Queries

The API distinguishes _bounded_ queries, which have well-defined sets of fields, from _unbounded_ queries, which have sets of fields that the API can’t determine in advance. For example, because the number of custom fields for an object isn’t predetermined, `FIELDS(CUSTOM)` and `FIELDS(ALL)` are considered unbounded. This table shows the support for `FIELDS()` in bounded and unbounded queries:

|                           | Bounded – FIELDS(STANDARD) | Unbounded – FIELDS(ALL) and FIELDS(CUSTOM)     |     |     |
| ------------------------- | -------------------------- | ---------------------------------------------- | --- | --- |
| Apex (inline and dynamic) | Supported                  | Not supported                                  |     |     |
| Bulk API 2.0              | Supported                  | Not supported                                  |     |     |
| CLI                       | Supported                  | Supported only if the result rows are limited. |     |     |
| SOAP API and REST API     | Supported                  | Supported only if the result rows are limited. |     |     |

## Limiting Result Rows

To limit the result rows, you can add any of these limits to the query:

- `LIMIT n` where `n` is less than or equal to 200. For example:

  ```soql
  SELECT FIELDS(ALL) FROM Contact LIMIT 200
  ```

- `WHERE Id IN idList` where `idList` is list of up to 200 IDs. For example:

  ```soql
  SELECT FIELDS(ALL) FROM Contact WHERE Id IN ('003R000000ATjnCIAT', '003R000000AZFUIIA5', '003R000000DkYoFIAV')
  ```

- `WHERE Id IS idList` where `idList` is a list of up to 200 ID tests joined with boolean operators. For example:

  ```soql
  SELECT FIELDS(ALL) FROM Contact WHERE Id = '003R000000ATjnCIAT' OR Id = '003R000000AZFUIIA5' OR Id = '003R000000DkYoFIAV'
  ```

## Salesforce CLI Example

This example uses `FIELDS()` with the Salesforce CLI:

```soql
sf data query --target-org DevHub --query "SELECT FIELDS(STANDARD) FROM Account"
```

This example assumes that the CLI is updated to work with version 51.0 or later of the API.

## REST API Example

This request uses `FIELDS()` with /query in REST API:

```soql
GET https://yourInstance.salesforce.com/services/data/v68.0/query?​q=SELECT+FIELDS(STANDARD)+FROM+Account
```

## SOAP API Example

This example uses `FIELDS()` with query() in SOAP API:

```soql
POST https://yourInstance.salesforce.com/services/Soap/c/68.0

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
          <urn:SessionHeader>
         <urn:sessionId>sessionId</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>SELECT FIELDS(STANDARD) FROM Account</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>
```

## Bulk API 2.0 Example

This request uses `FIELDS()` when creating a bulk query job:

```soql
POST https://yourInstance.salesforce.com/services/data/v68.0/jobs/query
{
  "operation": "query",
  "query": "SELECT FIELDS(STANDARD) FROM Account"
}

```

## Considerations for FIELDS()

Keep these considerations in mind when using the `FIELDS()` keyword.

- If you already know which fields you want to retrieve, you’ll get better performance by specifying them explicitly rather than using `FIELDS()` and retrieving more fields than you need.

- `FIELDS()` can cause errors if you use it with operators that require aggregation.


    -   For example, without `FIELDS()` this query works correctly:

        `SELECT Id, MIN(NumberOfEmployees) FROM Account GROUP BY Id`

        But adding `FIELDS()` to the query

        `SELECT FIELDS(ALL), MIN(NumberOfEmployees) FROM Account GROUP BY Id LIMIT 200`

        results in a “Field must be grouped or aggregated” error because it’s equivalent to

        `SELECT IsDeleted, <etc.>,MIN(NumberOfEmployees) FROM Account GROUP BY Id LIMIT 200`.

- If `FIELDS()` returns a large amount of data, use one of these methods to retrieve all the pages of results:


    -   In SOQL, if you use OFFSET and LIMIT in your query, the number of records returned may be less than LIMIT. Check the number of results that were returned and adjust OFFSET, as required. Do not just increment OFFSET by LIMIT.

    -   In Bulk API 2.0, use the Sforce-Locator response header that is returned in the job’s results.

    -   In REST API, use the nextRecordsUrl that is returned by /query and /queryAll.

    -   In SOAP API, use queryMore().

- If you use `SELECT FIELDS(CUSTOM)` on an object that doesn’t have any custom fields, the query results in an error.

  ```soql
  HTTP/1.1 400 Bad Request
  [
     {
        "message": "'FIELDS(...)' expansion function must result in at least one field being selected.",
        "errorCode" : "MALFORMED_QUERY"
     }
  ]

  ```

  If there are any fields included in the field list , there’s no error. For example, this query returns status code 200 even if the object contains no custom fields.

  ```soql
  SELECT Id, FIELDS(CUSTOM) FROM User LIMIT 200
  ```

- The list of fields returned by `FIELDS()` reflects the current state of the org's metadata and data model. Any changes to your org’s metadata or data model affects query performance and results.
