Newer Version Available

This content describes an older version of this product. View Latest

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
1curl https://MyDomainName.my.salesforce.com/services/data/v57.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
1{
2    "done" : true,
3    "totalSize" : 1,
4    "records" : 
5    [ 
6        {  
7            "attributes" : 
8            {    
9                "type" : "Merchandise__c",    
10                "url" : "/services/data/v57.0/sobjects/Merchandise__c/a00D0000008pQRAIX2"  
11            },  
12            "Name" : "Merchandise 1"
13        }, 
14    ]
15}

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:
1"nextRecordsUrl" : "/services/data/v57.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 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
1curl https://MyDomainName.my.salesforce.com/services/data/v57.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
1{
2    "done" : true,
3    "totalSize" : 3214,
4    "records" : [...]
5}