undelete()

Undeletes objects from the recycle bin.

Syntax

UndeleteResult[] = sfdc.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(). You can identify deleted records, including records deleted as the result of a merge, using the queryAll() call.

You should verify that an object can be undeleted before attempting to delete it. Some objects cannot be undeleted, for example, Account objects can be undeleted, but not AccountTeamMember objects. To verify that an object 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 header CallOptions.

Sample Code—Java

    public boolean 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");
            ID[] ids = new ID[qr.getSize()];
            for (int i = 0; i < ids.length; i++) {
                ids[i] = qr.getRecords()[i].getId();
            }
            // Invoke the undelete call
            UndeleteResult[] undeleteResults = binding.undelete(ids);
            // Process the results
            for (int i = 0; i < undeleteResults.length; i++) {
                UndeleteResult undeleteResult = undeleteResults[i];
                // Determine whether undelete succeeded or had errors
                if (undeleteResult.isSuccess()) {
                    System.out.println("Undeleted:" + undeleteResult.getId());
                } else {
                    // Handle the errors
                    Error[] errors = undeleteResult.getErrors();
                    ...
                }
 
            }
 
        }
        catch (UnexpectedErrorFault e) {
            System.out.println("Unexpected error encountered:\n\n" + e.getExceptionMessage());
            return false;
        }
        catch (InvalidSObjectFault e) {
            System.out.println("InvalidSObject encountered:\n\n" + e.getExceptionMessage());
            return false;            
        }
        catch (RemoteException e) {
            System.out.println("Remote exception encountered:\n\n" + e.getMessage());
            return false;            
        }

        return true;
 
    }

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 succesfully undelete, error message was: \n"
                   + ex.Message);
    }
}

Arguments

ids ID[] IDs of the objects to be restored.

Response

UndeleteResult

Faults

UnexpectedErrorFault

See Also:
delete()
© Copyright 2000-2008 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.