getDeleted()

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

Syntax

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

Usage

Use getDeleted() for data replication applications to retrieve a list of object instances 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 object 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 objects, consider the following rules and guidelines:

  • The specified startDate must chronologically precede the specified endDate value. The specified startDate cannot be the same value as, or later than, the specified endDate value. Otherwise, the API returns an INVALID_REPLICATION_DATE error.
  • Records are returned only if the user has access to them.
  • Results are returned for no more than 30 days previous to the day the call is executed (or earlier if an administrator has purged the recycle bin). If the purge has been performed before your getDeleted() call is executed, an INVALID_REPLICATION_DATE error is returned.
  • If latestDateCovered is less than endDate, the call will fail, returning an INVALID_REPLICATION_DATE error with the value of latestDateCovered.
  • Deleted records are written to a delete log, which getDeleted() accesses. A background process that runs every two hours purges records that have been in an organization's delete log for more than two hours if the number of records is above a certain limit. Starting with the oldest records, the process purges delete log entries until the delete log is back below the limit. This is done to protect Salesforce from performance issues related to massive delete logs. The limit is calculated using this formula:
        5000 * number of licenses in the organization

    For example, an organization with 1,000 licenses could have up to 5,000,000 (five million) records in the delete log before any purging took place. If purging has been performed before your getDeleted() call is executed, an INVALID_REPLICATION_DATE error is returned. If you get this exception, you should do a full pull of the table.

  • If you delete a large numbers of records, your data replication should run more frequently than every two hours to ensure all records are returned by getDeleted().
  • Client applications typically poll for changed data periodically. For important polling considerations, see Polling for Changes.
  • Certain objects cannot be replicated via the API. To replicate an object via the getDeleted() call, its object must be configured as replicateable (rReplicateable is true). To determine whether a given object can be replicated, your client application can invoke the describeSObjects() call on the object and inspect its replicateable property.
  • Development tools differ in the way that they handle time data. Some development tools report the local time, while others report only the Coordinated Universal Time (UTC) time. To determine how your development tool handles time values, refer to its documentation.

Basic Steps for Replicating Deleted Objects

You can replicate deleted objects 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 during which object were deleted.
  3. In the DeleteResult object, iterate through the returned array of DeletedRecord objects containing the ID of each deleted object 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 objects 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

private void getDeletedSample() {
  try {
    // You can use the timestamp from the service for a known point in time
    Calendar serverTime = binding.getServerTimestamp().getTimestamp();
    // Create a start time value for the call
    GregorianCalendar startTime = (GregorianCalendar) serverTime.clone();
    // Create an end time value for the call
    GregorianCalendar endTime = (GregorianCalendar) serverTime;
    // Subtract 5 mins from the server time so that we have a valid time frame.
    // You can use just about any timespan you want, 5 minutes is arbitrary
    endTime.add(GregorianCalendar.MINUTE, -5);
    System.out.println("Checking deletes at: " + startTime.getTime().toString());
    GetDeletedResult gdr = binding.getDeleted("Contact", startTime, endTime);
    // Check the number of records contained in the results, if more that 0,
    // then something was deleted in the 5 minute span
    if (gdr.getDeletedRecords() != null && gdr.getDeletedRecords().length > 0) {
      for (int i=0;i<gdr.getDeletedRecords().length;i++) {
        System.out.println(gdr.getDeletedRecords(i).getId() + " was deleted on " 
                           + gdr.getDeletedRecords(i).getDeletedDate().getTime().toString());
      }
    } else {
      System.out.println("No deletions from contacts in the last 5 minutes.");
    }
  } catch (Exception ex) {
    System.out.println("\nException caught, error message was: \n" + ex.getMessage());
  }
}

Sample Code—C#

private void getDeletedSample()
{
   DateTime endTime = binding.getServerTimestamp().timestamp;
    DateTime startTime = endTime.AddMinutes(-5));
    sforce.GetDeletedResult gdr = binding.getDeleted("Contact", startTime, endTime);
    
    if (gdr.deletedRecords.Length> 0) 
    {
        for (int i=0;i<gdr.deletedRecords.Length;i++) 
        {
            Console.WriteLine(gdr.deletedRecords[i].id + " was deleted on " 
                                + gdr.deletedRecords[i].deletedDate.ToString());
        }    
    } 
    else 
    {
        Console.WriteLine("No deleted contacts between " + startTime.ToString() + 
                            " and " + endTime.ToString() );
    }
}

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

See Also:
Data Replication
API Call Basics
https://wiki.apexdevnet.com/index.php/Sample_SOAP_Messages
© Copyright 2000-2008 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.