No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Restoring Deleted Records
After you have deleted records, the records are placed in the Recycle Bin for 15 days, after which they are permanently deleted. While the records are still in the Recycle Bin, you can restore them using the undelete operation. This is useful, for example, if you accidentally deleted some records that you want to keep.
Example
The following example undeletes an account named 'Trump'. The ALL ROWS keyword queries all rows
for both top level and aggregate relationships, including deleted
records and archived activities.
1swfobject.registerObject("clippy.codeblock-0", "9");Account a = new Account(Name='Trump');
2insert(a);
3insert(new Contact(LastName='Carter',AccountId=a.Id));
4delete a;
5
6Account[] savedAccts = [SELECT Id, Name FROM Account WHERE Name = 'Trump' ALL ROWS];
7try {
8 undelete savedAccts;
9} catch (DmlException e) {
10 // Process exception here
11}Undelete Considerations
Note the following
when using the undelete statement.
- You can undelete records that were deleted as the result of a merge, but the child objects will have been reparented, which cannot be undone.
- Use the ALL ROWS parameters with a SOQL query to identify deleted records, including records deleted as a result of a merge.
- See Referential Integrity When Deleting and Restoring Records.