Newer Version Available

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

queryAll()

Retrieves data from specified objects, including records that have been deleted or archived.

Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.

Note

Syntax

1QueryResult = connection.queryAll(string queryString);

Usage

Use queryAll() to identify the records that have been deleted because of a merge or delete. queryAll() has read-only access to the field isDeleted but is otherwise the same as query(). Use queryAll() in preparation to undelete records with the undelete() call.

To find records that have been deleted, specify isDeleted = true in the query string. For merged records, request the masterRecord. For example:
1SELECT id, isDeleted, masterRecordId FROM Account WHERE masterRecordId='100000000000Abc'

Filter on the isArchived field to find only the archived objects. You can update or delete archived records, but you can't update the isArchived field.

Because Salesforce doesn’t track changes to external data, queryAll() behaves the same as query() for external objects.

Note

Arguments

Name Type Description
queryString string Contains the SOQL query, which specifies the object to query, the fields to return, and any conditions for including a specific object in the query. See Salesforce SOQL and SOSL Reference Guide.

Sample Code—Java

This sample performs a query to get all the accounts, whether they’re deleted or not. It sets a custom batch size of 250 records. It fetches all batches of records by calling queryAll() the first time and then queryMore(). The names and the value of the isDeleted fields of all returned accounts are written to the console.

1public void queryAllRecords() {
2   // Setting custom batch size
3   connection.setQueryOptions(250);
4   
5   try {
6      String soqlQuery = "SELECT Name, IsDeleted FROM Account";
7      QueryResult qr = connection.queryAll(soqlQuery);
8      boolean done = false;
9      if (qr.getSize() > 0) {
10         System.out.println("Logged-in user can see a total of "
11               + qr.getSize()
12               + " contact records (including deleted records).");
13         while (!done) {
14            SObject[] records = qr.getRecords();
15            for (int i = 0; i < records.length; i++) {
16               Account account = (Account) records[i];
17               boolean isDel = account.getIsDeleted();
18               System.out.println("Account " + (i + 1) + ": "
19                     + account.getName() + " isDeleted = "
20                     + account.getIsDeleted());
21            }
22            if (qr.isDone()) {
23               done = true;
24            } else {
25               qr = connection.queryMore(qr.getQueryLocator());
26            }
27         }
28      } else {
29         System.out.println("No records found.");
30      }
31   } catch (ConnectionException ce) {
32      ce.printStackTrace();
33   }
34}

Sample Code—C#

This sample performs a query to get all the accounts, whether they’re deleted or not. It sets a custom batch size of 250 records. It fetches all batches of records by calling queryAll() the first time and then queryMore(). The names and the value of the isDeleted fields of all returned accounts are written to the console.

1public void queryAllRecords()
2{
3   // Setting custom batch size
4   QueryOptions qo = new QueryOptions();
5   qo.batchSize = 250;
6   qo.batchSizeSpecified = true;
7   binding.QueryOptionsValue = qo;
8
9   try
10   {
11      String soqlQuery = "SELECT Name, IsDeleted FROM Account";
12      QueryResult qr = binding.queryAll(soqlQuery);
13      Boolean done = false;
14      if (qr.size > 0)
15      {
16         Console.WriteLine("Logged-in user can see a total of "
17               + qr.size
18               + " contact records (including deleted records).");
19         while (!done)
20         {
21            sObject[] records = qr.records;
22            for (int i = 0; i < records.Length; i++)
23            {
24               Account account = (Account)records[i];
25               Boolean isDel = (Boolean)account.IsDeleted;
26               Console.WriteLine("Account " + (i + 1) + ": "
27                     + account.Name + " isDeleted = "
28                     + account.IsDeleted);
29            }
30            if (qr.done)
31            {
32               done = true;
33            }
34            else
35            {
36               qr = binding.queryMore(qr.queryLocator);
37            }
38         }
39      }
40      else
41      {
42         Console.WriteLine("No records found.");
43      }
44   }
45   catch (SoapException e)
46   {
47      Console.WriteLine("An unexpected error has occurred: " +
48                                 e.Message + "\n" + e.StackTrace);
49   }
50}

Response

QueryResult