getDeleted()

Retrieves the list of individual records that have been deleted within the given timespan for the specified object.

Syntax

GetDeletedResult = connection.getDeleted(string sObjectType, dateTime startDate, dateTime EndDate);

Usage

Use getDeleted() for data replication applications to retrieve a list of records that have been deleted from your organization’s data within the specified timespan. The getDeleted() call retrieves a GetDeletedResult object that contains an array of DeletedRecord objects containing the ID of each deleted record and the date/time (Coordinated Universal Time (UTC) time zone) on which it was deleted. Be sure to read Data Replication before using getDeleted() in your client applications. (For information on IDs, see ID Field Type.)

As of release 8.0, the getDeleted() call respects the user’s sharing model.

Rules and Guidelines

When replicating deleted records, consider the following rules and guidelines:

Basic Steps for Replicating Deleted Records

You can replicate deleted records using the following basic steps for each object:

  1. Optionally, determine whether the structure of the object has changed since the last replication request, as described in Checking for Structural Changes in the Object.
  2. Call getDeleted(), passing in the object and the relevant time span for deleted records.
  3. In the DeleteResult object, iterate through the returned array of DeletedRecord objects containing the ID of each deleted record and the date on which it was deleted (Coordinated Universal Time (UTC) time zone).
  4. Take the appropriate action on the local data to remove the deleted records or flag as deleted.
  5. Optionally, save the request time span for future reference. You should save the value of latestDateCovered.

A client application likely performs other tasks associated with data replication operations. For example, if an opportunity is closed, a client application might run a new revenue report. Similarly, if a task is completed, the process might log this in another system.

Sample Code—Java

This sample calls getDeleted() to get all accounts that were deleted in the last 60 minutes. It then writes the ID and the deleted date of each returned account to the console.

public void getDeletedRecords() {
   try {
      GregorianCalendar endTime = (GregorianCalendar)
         connection.getServerTimestamp().getTimestamp();
      GregorianCalendar startTime = (GregorianCalendar) endTime.clone();         
      // Subtract 60 minutes from the server time so that we have
      // a valid time frame.
      startTime.add(GregorianCalendar.MINUTE, -60);
      System.out.println("Checking deletes at or after: "
            + startTime.getTime().toString());
      
      // Get records deleted during the specified time frame.
      GetDeletedResult gdResult = connection.getDeleted("Account",
            startTime, endTime);
      
      // Check the number of records contained in the results,
      // to check if something was deleted in the 60 minute span.
      DeletedRecord[] deletedRecords = gdResult.getDeletedRecords();
      if (deletedRecords != null && deletedRecords.length > 0) {
         for (int i = 0; i < deletedRecords.length; i++) {
            DeletedRecord dr = deletedRecords[i];
            System.out.println(dr.getId() + " was deleted on "
                  + dr.getDeletedDate().getTime().toString());
         }
      } else {
         System.out.println("No deletions of Account records in "
               + "the last 60 minutes.");
      }
   } catch (ConnectionException ce) {
      ce.printStackTrace();
   }
}

Sample Code—C#

This sample calls getDeleted() to get all accounts that were deleted in the last 60 minutes. It then writes the ID and the deleted date of each returned account to the console.

public void getDeletedRecords()
{
   try
   {
      DateTime endTime = binding.getServerTimestamp().timestamp;
      // Subtract 60 minutes from the server time so that we have
      // a valid time frame. DateTime startTime = endTime.AddMinutes(-60); Console.WriteLine("Checking deletes at or after: " + startTime.ToLocalTime().ToString()); // Get records deleted during the specified time frame. GetDeletedResult gdResult = binding.getDeleted("Account", startTime, endTime); // Check the number of records contained in the results,
      // to check if something was deleted in the 60 minute span. DeletedRecord[] deletedRecords = gdResult.deletedRecords; if (deletedRecords != null && deletedRecords.Length > 0) { for (int i = 0; i < deletedRecords.Length; i++) { DeletedRecord dr = deletedRecords[i]; Console.WriteLine(dr.id + " was deleted on " + dr.deletedDate.ToLocalTime().ToString()); } } else { Console.WriteLine("No deletions of Account records in " + "the last 60 minutes."); } } catch (SoapException e) { Console.WriteLine("An unexpected error has occurred: " + e.Message + "\n" + e.StackTrace); } }

Arguments

Name Type Description
sObjectTypeEntityType string Object type. The specified value must be a valid object for your organization. See sObject.
startDate dateTime Starting date/time (Coordinated Universal Time (UTC)—not local— timezone) of the timespan for which to retrieve the data. The API ignores the seconds portion of the specified dateTime value (for example, 12:30:15 is interpreted as 12:30:00 UTC).
endDate dateTime Ending date/time (Coordinated Universal Time (UTC)—not local— timezone) of the timespan for which to retrieve the data. The API ignores the seconds portion of the specified dateTime value (for example, 12:35:15 is interpreted as 12:35:00 UTC).

Limits

There are record limits on the result GetDeletedResult:

You can correct the error by choosing start and end dates that are closer together.

Response

GetDeletedResult

Faults

InvalidSObjectFault

UnexpectedErrorFault

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