Managing data in Microsoft Dataverse is critical, especially when it comes to deleted records. Accidental deletions or necessary cleanups are common, and knowing how to restore these records can save time and maintain data integrity. This blog post dives into how you can restore deleted records in Dataverse, using both the Power Platform Admin Center and the Dataverse SDK, covering use cases and best practices.
Why Restoring Deleted Records Matters
In complex business systems, deleted records might hold crucial information. Sometimes, data is removed accidentally, or maybe it’s necessary to retrieve data after a systematic cleanup. Dataverse offers tools to recover this information and handle it in ways that align with your organization’s data retention and recovery needs.
The Two-Step Deletion Process in Dataverse
Microsoft Dataverse follows a two-step deletion model:
- Soft Delete: When a record is deleted, it is first moved to a “soft delete” state where it remains in the system but is not accessible via standard operations.
- Hard Delete: After a retention period, these records are permanently deleted.
This model ensures records can be restored if needed, up until the hard delete occurs.
Restoring Deleted Records through Power Platform Admin Center
For many administrators, the Power Platform Admin Center provides a straightforward approach to restore records. Here’s how:
- Access the Deleted Records: Go to the Power Platform Admin Center, select your environment, then navigate to the “Deleted Records” option.
- Select Records to Restore: Browse or search for specific records that were deleted within the retention window. Note that once the retention period has expired, the records will no longer be available for restoration here.
- Initiate Restore: Select the desired records and click “Restore.” This will reinstate the records to their original state, retaining all their previous attributes and relationships.
Note: The Power Platform Admin Center is best suited for recovering records that are managed through regular administrative processes and smaller, one-off recovery needs.
Restoring Deleted Records Using the Dataverse SDK
For more complex scenarios—especially when automated restoration or integration with custom applications is required—the Dataverse SDK offers a programmatic approach to restoring records. Below is an example to get you started:
Prerequisites
- Access to the SDK for Dataverse.
- Appropriate permissions to execute the recovery code.
Code Example for Restoration
The following C# example demonstrates how to use the SDK to retrieve and restore a soft-deleted record. This method queries the data for deleted records and reinstates them:
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
// Define the Dataverse service connection
IOrganizationService service = ... // Set up your service connection
// Specify the logical name of the record type and ID of the deleted record
string entityName = "account";
Guid deletedRecordId = new Guid("your-deleted-record-id");
Entity retrievedEntity = service.Retrieve(entityName, deletedRecordId, new ColumnSet(true));
// To restore, re-activate or create a new instance with the same data
Entity restoredEntity = new Entity(entityName)
{
Id = retrievedEntity.Id,
Attributes = retrievedEntity.Attributes
};
// Re-assign status or any necessary field modifications, if applicable
service.Update(restoredEntity);
Tip: Use
ColumnSet(true)to retrieve all columns, ensuring you recover the complete data from the deleted record.
This approach allows developers to build automated processes for restoring data without manual intervention, ideal for bulk restoration scenarios or when an external system needs to trigger record restoration.
Use Cases for Restoring Records in Dataverse
- Accidental Deletions: Recovery of records deleted by users mistakenly can be handled either through the admin center or SDK, depending on the volume of records.
- System-Driven Cleanups: Some organizations set automated cleanups on stale or unengaged records but may want to retain an option for recovery.
- Data Retention Compliance: In certain cases, regulatory compliance may require records to be reinstated temporarily for audits or legal inquiries. The SDK option enables this recovery process seamlessly.
Best Practices for Managing Deleted Records in Dataverse
- Define Retention Policies: Clearly outline how long deleted records will remain soft-deleted before being permanently removed.
- Automation with SDK: Use the SDK for bulk recovery scenarios or for building automated processes. This can save time and reduce the risk of data loss in repeated recovery situations.
- Security Considerations: Limit access to the restore capabilities, ensuring only authorized personnel can recover sensitive data.
FAQs on Restoring Deleted Records
Q: Can all records be restored after deletion?
A: Only records within the soft-deletion retention window can be restored. After the retention period, records are permanently removed.
Q: Is it possible to retrieve related records automatically when a primary record is restored?
A: Related records can be restored, but you must manage dependencies carefully. Using the SDK allows for handling these relationships programmatically.
Q: How can I ensure compliance while restoring deleted records?
A: Audit logs should be enabled, capturing each restoration action. This provides visibility into who restored records and why, ensuring adherence to compliance requirements.
Q: Are restored records identical to their pre-deletion state?
A: Restored records retain the attributes and relationships they held at the point of deletion. Ensure all custom attributes are included in the recovery, especially with the SDK.
Final Thoughts
Recovering deleted records in Microsoft Dataverse is essential for maintaining data integrity and supporting compliance standards. With both the Power Platform Admin Center and the SDK for Dataverse, administrators and developers have flexible options to restore records efficiently and accurately. Whether you’re handling accidental deletions or supporting complex automated recovery processes, Dataverse provides robust solutions to meet your data management needs.
