Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
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. If you accidentally deleted some records that you want to keep, restore them from the Recycle Bin.
Example
1Account a = new Account(Name='Universal Containers');
2insert(a);
3insert(new Contact(LastName='Carter',AccountId=a.Id));
4delete a;
5
6Account[] savedAccts = [SELECT Id, Name FROM Account WHERE Name = 'Universal Containers' ALL ROWS];
7try {
8 undelete savedAccts;
9} catch (DmlException e) {
10 // Process exception here
11}Undelete Considerations
- You can undelete records that were deleted as the result of a merge. However, the merge reparents the child objects, and that reparenting can’t be undone.
- To identify deleted records, including records deleted as a result of a merge, use the ALL ROWS parameters with a SOQL query.
- See Referential Integrity When Deleting and Restoring Records.