Retrieves the list of individual records that have been deleted within the given timespan for the specified object.
GetDeletedResult = connection.getDeleted(string sObjectType, dateTime startDate, dateTime EndDate);
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.
When replicating deleted records, consider the following rules and guidelines:
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.
You can replicate deleted records using the following basic steps for each object:
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.
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(); } }
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); } }
| 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). |
There are record limits on the result GetDeletedResult:
You can correct the error by choosing start and end dates that are closer together.