How to restore deleted records from your CRM system
A few weeks ago, I made a thoughtless mistake in data synchronization between the ERP and CRM systems. A request was made for synchronization to delete CRM records based on an ID. Nothing special so far. I developed my code for deletion, tested it with different entities and made a rollout. Unfortunately, there was one scenario that I forgot to test. Thus, my code deleted the wrong records.
After a short panic attack, I tried to figure out which records were deleted. Since we are dealing with CRM Online, it is not possible to take a look into the database. So what else could I do? Then, I found out that the Audit for deletion is more powerful than I thought.
Step by step: restore your deleted records from the CRM system
For a moment, it looked like “Oh CRM audited that I deleted a very important lead.” Later, I figured out that the record might not be available as an existing record, but the information of all audited fields was still there:
So, I started searching for a way to get this information. In the CRM SDK I found the RetrieveAuditDetailsRequest. This Request requires only the audit Id to get the audit details. Therefore, you first have to query for audits. In my case: leads deleted on 2/4/2016.
After that, you have to execute the RetrieveAuditDetailsRequest with the Id of the audit entity previously queried. The RetrieveAuditDetailsResponse contains the AuditDetail, which being casted to AttributeAuditDetail, contains the deleted Entity as OldValue property.
Now, you can do what you have to do with this information, e.g. restore the data via creating the old value again.
I think with this knowledge it is pretty easy to restore deleted data in CRM. Very important in this context is of course the enabled auditing. Furthermore, fields which are not enabled for auditing will not be restored either.
If you’re looking to solve one of the most common issues seen in CRM customization, namely deleting obsolete fields in the productive system (managed), you’ll find your question answered in this article.