undelete()

Undeletes records from the Recycle Bin.

Syntax

UndeleteResult[] = connection.undelete(ID[] ids );
                    

Usage

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.

Note

Starting with API version 15.0, if you specify a value for a field that contains a string, and the value is too big for the field, the call fails and an error is returned. In previous versions of the API the value was truncated and the call succeeded. If you wish to keep the old behavior with versions 15.0 and later, use the AllowFieldTruncationHeader SOAP header.

This call supports the AllOrNoneHeader, AllowFieldTruncationHeader, and CallOptions headers.

Rollback on Error

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.

Sample Code—Java

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();
  }
}

Sample Code—C#

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);
    }
}

Arguments

Name Type Description
ids ID[] IDs of the records to be restored.

Response

UndeleteResult

Faults

UnexpectedErrorFault

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