What happens when you delete a record in Salesforce? What are some important considerations? And how do you recover deleted records if a record...or multiple records were deleted by accident? Deleting records is a part of a Salesforce administrator day-to-day responsibilities. Whether it is single records created by mistake, or a mass delete to undo imports. It is important to know the tools available to you, as well as how to undo unintended changes. Deleting, and especially mass deleting, records should always be done with consideration.
What Happens When You Delete a Record In Salesforce?
When you delete a record in Salesforce, there are several things that happen behind the scenes. The first thing that happens is that all fields on the record are set to null. This includes any custom formulas, field validation rules, and triggers. If you have an email template for your contact object, then those templates will also be removed. Next, the record is marked as inactive, so that it can no longer be viewed. Finally, the record is moved to the Recycle Bin.
When you delete a record, it does not actually get permanently deleted from the database. Instead, it gets put into the recycle bin, which is a temporary holding area for records that have been deleted accidentally. Once the record has been in the Recycle Bin for 30 days, it is automatically purged from the system.
How do you delete records in Salesforce?
Depending on your degree of access, there are many ways to delete records in Salesforce. You can use the delete button on a single record. You can delete from a list view. You can use the Mass Delete Records in Setup, You can use Data Loader or other IO Tools to delete records. You can even delete records using Apex or an App from the AppExchange. No matter what you choose, records make a stop in the Recycle Bin for 30 days before it is permanently deleted. You can also go to the Recycle Bin to permanently delete records immediately (Modify All Data permission needed to purge the Recycle Bin).
Considerations when deleting records in Salesforce.
The delete operation supports cascading deletion in Salesforce. That means, if you delete a parent record, all related child records with a master-detail relationship are deleted. On a standard object like account, deleting an account record would also delete related contacts, opportunities, contracts, etc.
Records can also be orphaned in a deletion. For example, a parent/child model have a lookup relationship between parent/child object. In this case, if the parent record is deleted, the child record would not be automatically deleted and the field history tracking for the child record does not record the deletion. Child records in a lookup relationship are not automatically deleted with the parent.
If a child record is deleted and the parent record is subsequently deleted, the child record is permanently deleted even if the parent record is undeleted.
Restoring records from a backup file is possible, but often times it is complicated to restore records with the appropriate relationship, i.e. parents, children, grandchildren, orphan records.
A report cannot be deleted if it is referenced in a dashboard. A report folder cannot be deleted if there are any reports in the folder, including reports that are soft deleted. Reports have to permanently deleted for their associated folder to be removed.
How do you recover deleted records?
Within 30 days, and as long as no one else has permanently deleted the record, a Salesforce record is recoverable from the Recycle Bin. Just check the box next to the record, and click Undelete. Salesforce editions with API access can also mass undelete records using client tools such as Workbench.
Child records in a master detail relationship will not appear in the Recycle Bin, only its parent will. Restoring the parent record will automatically restore any child records that were a part of the cascade delete. This also means that the relationships between these records are restored.
Even if a record has been purged from the Recycle Bin, it might still be visible through API until it is purged from the organization. Users with View All Data and API access can check for records in this state by using Export All in Data Loader, and filtering on isDeleted = True. If the record is not visible in Recycle Bin, but is visible in this query, it can be exported using Data Loader and recreated. A recreated record will have a new Salesforce ID.
If records are hard deleted, they can be recovered from a backup (such as Salesforce Backup & Restore), data export, or full sandbox. You might need the help of a developer.
Records can also be restored from a previous Data Export. However this process can be complicated depending on the scope of deletion.
If your organization has a full sandbox without excluded objects, data can be downloaded from the sandbox and recreated in production. You must first remove the sandbox before restoring data.
Deleting, and mass deleting, records is going to be a part of the job of CRM administrator. It is important to know how records are connected within your org. You can find times where a recovery will not be perfectly smooth. Sometimes the mass delete is a big accident. It is important to note that recovering data is time sensitive, and you can investigate what happened in conjunction. If you know that you need to recover data, work on the recovery first.
What are your thoughts and considerations when deleting records in Salesforce? Join the conversation by subscribing to Salesforcezen.com and join us for our Live Q&As. Share your thoughts on everything Salesforce. Go to
https://www.SuperUserAcademy.com/liveQAcall to register, it's free.
Apex Code to Delete Records (Salesforce Community Forum)
Effects of Detachment on Connect Objects in a "Master-Detail" Relationship (Salesforce Help)
Insert, Update, Delete Records (Salesforce Help)
Delete Multiple Records and Reports (Salesforce Help)
Recover Records and Data in Salesforce (Salesforce Help)