How does the Salesforce recycle bin handle accidental deletions of critical sales records?
Answer
Basics: Delete in Salesforce is a soft delete: the record is flagged IsDeleted and hidden from normal queries and views. Users can restore their own records; admins can see everyone's.
How it works:
- User deletes a record; it moves to the Recycle Bin (Lightning: App Launcher > Recycle Bin).
- Related child records that were deleted by cascade (for example contacts, opportunities of an Account) are restored together when you undelete the parent, where Salesforce supports it.
- Retention is 15 days; after that records are purged. The bin has a capacity of 25 times your storage MB in records; if exceeded, the oldest records are removed earlier.
- Admins use the All Recycle Bin view (needs Modify All Data) to recover other users' records.
- Apex and API support undelete, and queries with ALL ROWS return soft-deleted records.
Advanced / deep dive: Hard delete (Bulk API hard delete, or Database.emptyRecycleBin) skips the bin and cannot be undone except via a backup. Deleted records are not accessible via normal reports. Related lookups to a deleted record are cleared depending on the lookup delete setting (Clear the value, Don't allow deletion, Delete). Master-detail children are deleted with the master and restored with it. Merged losing records go to the bin. Salesforce Backup and Restore, or Data Export, covers recovery after the 15 days. Deletion fires triggers (before/after delete) and undeletion fires undelete triggers, which should rebuild rollups.
Code / config example:
List<Account> gone = [SELECT Id, Name FROM Account
WHERE IsDeleted = true LAST_N_DAYS:
ALL ROWS];
Database.UndeleteResult[] res = Database.undelete(gone, );