Newer Version Available
queryAll()
Retrieves data from specified objects, whether or not they have been deleted.
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; otherwise it is the same as query().
1SELECT id, isDeleted, masterRecordId FROM Account WHERE masterRecordId='100000000000Abc'You can use queryAll() to query on all Task and Event records, archived or not. You can also filter on the isArchived field to find only the archived objects. You cannot use query() as it automatically filters out all records where isArchived is set to true. You can update or delete archived records, though you cannot update the isArchived field. If you use the API to insert activities that meet the criteria listed below, the activities will be archived during the next run of the archival background process.
Because Salesforce doesn’t track changes to external data, queryAll() behaves the same as query() for external objects.
For additional information about using queryAll, see query().
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}Arguments
| Name | Type | Description |
|---|---|---|
| queryString | string | Query string that specifies the object to query, the fields to return, and any conditions for including a specific object in the query. For more information, see the Salesforce SOQL and SOSL Reference Guide. |