Undeletes records from the Recycle Bin.
Use this call to restore any deleted record that is undeletable. Undeletable records include those in the Recycle Bin. Records can be put in the Recycle Bin as the result of a merge() or delete() call. You can identify deleted records, including records deleted as the result of a merge, using the queryAll() call.
You should verify that a record can be undeleted before attempting to delete it. Some records cannot be undeleted, for example, Account records can be undeleted, but not AccountTeamMember records. To verify that a record can be undeleted, check that the value of the undeletable flag in the DescribeSObjectResult for that object is set to true.
Since a delete call cascade-deletes child records, an undelete call will undelete the cascade-deleted records. For example, deleting an account will delete all the contacts associated with that account.
You can undelete records that were deleted as the result of a merge, but the child objects will have been re-parented, which cannot be undone.
This call supports the AllOrNoneHeader, AllowFieldTruncationHeader, and CallOptions headers.
The AllOrNoneHeader header allows you to roll back all changes unless all records are processed successfully. This header is available in API version 20.0 and later. The default behavior is to allow partial success of a call: records without errors are committed, while records with errors are marked as failed in the call results.
public void undeleteRecords(String[] ids) { try { String soqlQuery = "SELECT id, SystemModstamp FROM " + "Account WHERE IsDeleted=true " + "ORDER BY SystemModstamp DESC LIMIT 5"; QueryResult qResult = connection.queryAll(soqlQuery); for (UndeleteResult result : connection.undelete(ids)) { if (result.isSuccess()) { System.out.println("Undeleted Account ID: " + result.getId()); } else { Error[] errors = result.getErrors(); if (errors.length > 0) { System.out.println("Error code: " + errors[0].getStatusCode()); System.out.println("Error message: " + errors[0].getMessage()); } } } } catch (ConnectionException ce) { ce.printStackTrace(); } }
private void undeleteSample() { try { // Get the last few deleted Account ids. QueryResult qr = binding.queryAll("SELECT id, SystemModstamp From Account " + "WHERE isDeleted=true ORDER BY SystemModstamp DESC LIMIT 5"); String[] ids = new String[qr.size] ; for (int i = 0; i < ids.Length; i++) { ids[i] = qr.records[i] .Id; } UndeleteResult[] undeleteResults = binding.undelete(ids); // Process the results for (int i = 0; i < undeleteResults.Length; i++) { UndeleteResult undeleteResult = undeleteResults[i] ; if (undeleteResult.success) { Console.WriteLine("Undeleted:" + undeleteResult.id); } else { // Handle the errors Error[] errors = undeleteResult.errors; } } } catch (Exception ex) { Console.WriteLine("\nFailed to successfully undelete, error message was: \n" + ex.Message); } }
| Name | Type | Description |
|---|---|---|
| ids | ID[] | IDs of the records to be restored. |