queryAll()

Retrieves data from specified objects, whether or not they have been deleted.

Syntax

QueryResult = 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().

To find records that have been deleted (in preparation for undeleting them with the undelete() call), specify isDeleted = true in the query string, and for merged records, request the masterRecord. For example:
SELECT 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, the queryAll() call behaves exactly 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.

public void queryAllRecords() {
   // Setting custom batch size
   connection.setQueryOptions(250);
   
   try {
      String soqlQuery = "SELECT Name, IsDeleted FROM Account";
      QueryResult qr = connection.queryAll(soqlQuery);
      boolean done = false;
      if (qr.getSize() > 0) {
         System.out.println("Logged-in user can see a total of "
               + qr.getSize()
               + " contact records (including deleted records).");
         while (!done) {
            SObject[] records = qr.getRecords();
            for (int i = 0; i < records.length; i++) {
               Account account = (Account) records[i];
               boolean isDel = account.getIsDeleted();
               System.out.println("Account " + (i + 1) + ": "
                     + account.getName() + " isDeleted = "
                     + account.getIsDeleted());
            }
            if (qr.isDone()) {
               done = true;
            } else {
               qr = connection.queryMore(qr.getQueryLocator());
            }
         }
      } else {
         System.out.println("No records found.");
      }
   } catch (ConnectionException ce) {
      ce.printStackTrace();
   }
}

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.

public void queryAllRecords()
{
   // Setting custom batch size
   QueryOptions qo = new QueryOptions();
   qo.batchSize = 250;
   qo.batchSizeSpecified = true;
   binding.QueryOptionsValue = qo;

   try
   {
      String soqlQuery = "SELECT Name, IsDeleted FROM Account";
      QueryResult qr = binding.queryAll(soqlQuery);
      Boolean done = false;
      if (qr.size > 0)
      {
         Console.WriteLine("Logged-in user can see a total of "
               + qr.size
               + " contact records (including deleted records).");
         while (!done)
         {
            sObject[] records = qr.records;
            for (int i = 0; i < records.Length; i++)
            {
               Account account = (Account)records[i];
               Boolean isDel = (Boolean)account.IsDeleted;
               Console.WriteLine("Account " + (i + 1) + ": "
                     + account.Name + " isDeleted = "
                     + account.IsDeleted);
            }
            if (qr.done)
            {
               done = true;
            }
            else
            {
               qr = binding.queryMore(qr.queryLocator);
            }
         }
      }
      else
      {
         Console.WriteLine("No records found.");
      }
   }
   catch (SoapException e)
   {
      Console.WriteLine("An unexpected error has occurred: " +
                                 e.Message + "\n" + e.StackTrace);
   }
}

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.

Response

QueryResult

Faults

MalformedQueryFault

InvalidSObjectFault

InvalidFieldFault

UnexpectedErrorFault

© Copyright 2000–2014 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.