---
schema_version: "1"
id: 18136ae71cbeed1856c0516714825c6ef6d7ebf08855f1c2ce2ffcc25d7eebba
title: Execute a SOQL Query
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/api-rest/guides/do-me/dome-query.md
canonical_url: https://developer.salesforce.com/docs/platform/api-rest/guide/dome-query.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9003e3cbcbdc4c328d4968c4ef7c9fa6363e90f539fd84a51e34644775b8accc
products:
  - REST API Developer Guide
  - Platform Developer Content
---

# Execute a SOQL Query

Use the Query resource to execute a SOQL query that returns all the results in a single response, or if needed, returns part of the results and a locator used to retrieve the remaining results.

The following query requests the value from `name` fields from all Account records.

**Example usage for executing a query**

```nolang
curl https://MyDomainName.my.salesforce.com/services/data/v68.0/query/?q=SELECT+name,id+from+Account -H "Authorization: Bearer token"
```

**Example request body for executing a query:** none required

**Example response body for executing a query**

```nolang
{
    "done" : true,
    "totalSize" : 14,
    "records" : 
    [ 
        {  
            "attributes" : 
            {    
                "type" : "Account",    
                "url" : "/services/data/v68.0/sobjects/Account/001D000000IRFmaIAH"  
            },  
            "Name" : "Test 1"
        }, 
        {  
            "attributes" : 
            {    
                "type" : "Account",    
                "url" : "/services/data/v68.0/sobjects/Account/001D000000IomazIAB"  
            },  
            "Name" : "Test 2"
        }, 

        ...

    ]
}
```

## Retrieving the Remaining SOQL Query Results

If the initial query returns only part of the results, the end of the response contains a field called `nextRecordsUrl`:

```nolang
"nextRecordsUrl" : "/services/data/v68.0/query/01gD0000002HU6KIAW-2000"
```

In such cases, request the next batch of records and repeat until all records have been retrieved. These requests use `nextRecordsUrl`, and don't include any parameters.

**Example usage for retrieving the remaining query results**

```nolang
curl https://MyDomainName.my.salesforce.com/services/data/v68.0/query/01gD0000002HU6KIAW-2000 -H "Authorization: Bearer token"
```

**Example request body for retrieving the remaining query results:** none required

**Example response body for retrieving the remaining query results**

```nolang
{
    "done" : true,
    "totalSize" : 3214,
    "records" : [...]
}
```

