queryAll()

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

Syntax

QueryResult = sfdc.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.

For additional information about using queryAll, see query().

Sample Code—Java

private void querySample() {
  QueryResult qr = null;
  QueryOptions qo = new QueryOptions();
  qo.setBatchSize(new Integer(250));
  binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), 
        "QueryOptions", qo);
  try {
    qr = binding.queryAll("select FirstName, LastName, IsDeleted from Contact");
    boolean done = false;
    if (qr.getSize() > 0){
      System.out.println("Logged-in user can see " + qr.getRecords().length + 
           " contact records (including deleted records).");
      while (!done) {
        for (int i=0;i<qr.getRecords().length;i++) {
          Contact con = (Contact)qr.getSize(i);
          String fName = con.getFirstName();
          String lName = con.getLastName();
          boolean isD = con.isDeleted();
          if (fName == null)
            System.out.println("Contact " + (i + 1) + ": " + lName + " isDeleted = " + isD);
          else
            System.out.println("Contact " + (i + 1) + ": " + fName + " " + lName +  
                 " isDeleted = " + isD);
        }
        if (qr.isDone()) {
          done = true;
        } else {
          qr = binding.queryMore(qr.getQueryLocator());
        }
      }
    }
    else {
      System.out.println("No records found.");
    }
    System.out.println("\nQuery succesfully executed.");
  }
  catch (RemoteException ex) {
    System.out.println("\nFailed to execute query succesfully, error message was: 
         \n" + ex.getMessage());  }
}

Sample Code—C#

private void queryAllSample()
{
    QueryResult qr = null;
    QueryOptions qo = new QueryOptions();
    qo.batchSize = 250;
    binding.QueryOptionsValue = qo;
    try
    {
        qr = binding.queryAll("Select FirstName, LastName,IsDeleted from Account");
        if (qr.size > 0)
        {
            Console.WriteLine("Logged-in user can see " + qr.records.Length + " Account");
            while (true)
            {
                for (int i = 0; i < qr.records.Length; i++)
                {
                    Account account = (Account)qr.records[i];
                    String name = account.Name;
                    bool? isD = account.IsDeleted;
                    Console.WriteLine("Account " + (i + 1) + ": " + name + "isDeleted = " 
                           + isD);
                    if (qr.done)
                    {
                        break;
                    }
                    else
                    {
                        qr = binding.queryMore(qr.queryLocator);
                    }
                }
            }
        }
        else
        {
            Console.WriteLine("No records found");
        }
        Console.WriteLine("QueryAll successfully executed.");
    }
            catch (Exception ex)
    {
                Console.WriteLine("\nFailed to execute query succesfully, error message 
                       was: \n" + ex.Message);
    }
}

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 Salesforce Object Query Language (SOQL).

Response

QueryResult

Faults

MalformedQueryFault

InvalidSObjectFault

InvalidFieldFault

UnexpectedErrorFault

See Also:
API Call Basics
queryMore()
© Copyright 2000-2008 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.