---
schema_version: "1"
id: 5bb569d0e847d23a1a76da7a4c461b78d9a906c5055eafffa97798ab02dbac3b
title: Execute a SOQL Query that Includes Deleted Items
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/api-rest/guides/do-me/dome-queryall.md
canonical_url: https://developer.salesforce.com/docs/platform/api-rest/guide/dome-queryall.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 74b6a4968943afb22afc5cf4d6b1b2ca7f6c57ce61a635dcfcf245c23f142b73
products:
  - REST API Developer Guide
  - Platform Developer Content
---

# Execute a SOQL Query that Includes Deleted Items

Use the QueryAll resource to execute a SOQL query that includes information about records that have been deleted because of a merge or delete. Use QueryAll rather than Query, because the Query resource will automatically filter out items that have been deleted.

The following query requests the value from the `Name` field from all deleted Merchandise__c records, in an organization that has one deleted Merchandise__c record. The same query using Query instead of QueryAll would return no records, because Query automatically filters out any deleted record from the result set.

**Example usage for executing a query for deleted Merchandise__c records**

```nolang
curl https://MyDomainName.my.salesforce.com/services/data/v68.0/queryAll/?q=SELECT+Name+from+Merchandise__c+WHERE+isDeleted+=+TRUE -H "Authorization: Bearer token"
```

**Example request body for executing a query:** none required

**Example response body for executing a query**

```nolang
{
    "done" : true,
    "totalSize" : 1,
    "records" : 
    [ 
        {  
            "attributes" : 
            {    
                "type" : "Merchandise__c",    
                "url" : "/services/data/v68.0/sobjects/Merchandise__c/a00D0000008pQRAIX2"  
            },  
            "Name" : "Merchandise 1"
        }, 
    ]
}
```

## Retrieving the Remaining SOQL Query Results

If the initial query returns only part of the results, the end of the response will contain a field called `nextRecordsUrl`. For example, you might find this attribute at the end of your query:

```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 do not include any parameters.

Although the `nextRecordsUrl` has `query` in the URL, it still provides the remaining results from the initial QueryAll request. The remaining results include deleted records that matched the initial query.

**Example usage for retrieving the remaining 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 results:** none required

**Example response body for retrieving the remaining results**

```nolang
{
    "done" : true,
    "totalSize" : 3214,
    "records" : [...]
}
```

