Florian Ludwig
Apr 26, 2016 | Last updated: Dec 16, 2022
Expert articles | 3 min read

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

Audit summary view

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:

Overview of all audited fields

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.

RetrieveAuditDetailsRequest in the CRM SDK

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.

Information stored in the AuditDetail

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.