Newer Version Available
undelete()
Syntax
Usage
Use this call to restore any deleted record that is undeletable, including those records 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 must 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 undeletes the cascade-deleted records. For example, deleting an account deletes all the contacts associated with that account.
You can undelete records that were deleted as the result of a merge, but the child objects are reparented, which can’t be undone.
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. Lets a call roll back all changes unless all records are processed successfully.
Sample Code—Java
This sample calls queryAll() to get the last five deleted accounts. It then passes the IDs of these accounts to undelete(), which restores these accounts. Finally, it checks the results of the call and writes the IDs of the restored accounts or any errors to the console.
Sample Code—C#
This sample calls queryAll() to get the last five deleted accounts. It then passes the IDs of these accounts to undelete(), which restores these accounts. Finally, it checks the results of the call and writes the IDs of the restored accounts or any errors to the console.
Arguments
| Name | Type | Description |
|---|---|---|
| ids | ID[] | IDs of the records to be restored. |