Skip to content

Commit b2a6500

Browse files
committed
edits
1 parent d634c7b commit b2a6500

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

powerapps-docs/developer/data-platform/restore-deleted-records.md

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ static EntityCollection GetDeletedAccountRecordsQueryExpression(IOrganizationSer
7373
With Web API, you can retrieve records using FetchXml or OData syntax.
7474

7575
> [!NOTE]
76-
> Currently, you can only retrieve deleted records using FetchXml.
76+
> Currently, with Web API you can only retrieve *deleted* records using FetchXml.
77+
78+
When you retrieve data using FetchXml, set the [fetch element](fetchxml/reference/fetch.md) `datasource` attribute to '`bin`' when you retrieve records.
7779

7880
This `Get-DeletedAccountRecords` PowerShell function returns up to three deleted account records.
7981

@@ -290,9 +292,16 @@ function Restore-AccountRecord {
290292

291293
---
292294

293-
### Errors that might occur when restoring records
295+
### Best practices when restoring records
296+
297+
The following are issues you can avoid when restoring records:
298+
299+
- [Restore related records before restoring primary record](#restore-related-records-before-restoring-primary-record)
300+
- [Don't specify primary key values when creating records](#dont-specify-primary-key-values-when-creating-records)
301+
- [Records with matching alternate key values will block restore](#records-with-matching-alternate-key-values-will-block-restore)
302+
- [Records using removed Choice options can't restored](#records-using-removed-choice-options-cant-restored)
303+
- [Primary Key Violation on Delete](#primary-key-violation-on-delete)
294304

295-
The following errors might occur when restoring records.
296305

297306
#### Restore related records before restoring primary record
298307

@@ -334,7 +343,7 @@ If you delete an optionset option, and that option was used in a deleted record,
334343

335344
#### Primary Key Violation on Delete
336345

337-
If the record with same primary key was already deleted before, copy to Recycle Bin is ignored for the record. To enforce all deleted items are stored in Recycle Bin, you can set the `DoNotEnforcePrimaryKeyOrgSettingRecycleBin` setting using the [OrgDBOrgSettings tool for Microsoft Dynamics CRM](/power-platform/admin/environment-database-settings).
346+
If the record with same primary key was already deleted before, copy to recycle bin is ignored for the record. To enforce all deleted items are stored in recycle bin, you can set the `DoNotEnforcePrimaryKeyOrgSettingRecycleBin` setting using the [OrgDBOrgSettings tool for Microsoft Dynamics CRM](/power-platform/admin/environment-database-settings).
338347

339348
After enabling this setting, you might receive the following error:
340349

@@ -525,7 +534,7 @@ function Set-CleanupIntervalInDays{
525534
To disable the recycle bin for a table, disable the `recyclebinconfig` record for the table by setting the [statecode](reference/entities/recyclebinconfig.md#BKMK_statecode) and [statuscode](reference/entities/recyclebinconfig.md#BKMK_statuscode) properties to their **Inactive** values: `2` and `1` respectively.
526535

527536
> [!NOTE]
528-
> The following queries compare the `EntityId` value against the [Entity.EntityId](reference/entities/entity.md#-entityid) column value, which stores the table `EntityId`.
537+
> The following queries compare the `EntityId` value against the [Entity.EntityId](reference/entities/entity.md#-entityid) column value, which stores the table [EntityMetadata.MetadataId ](/dotnet/api/microsoft.xrm.sdk.metadata.metadatabase.metadataid).
529538
530539
### [SDK for .NET](#tab/sdk)
531540

@@ -546,8 +555,16 @@ static void DisableRecycleBinForTable(
546555
{
547556
ColumnSet = new ColumnSet("recyclebinconfigid")
548557
};
549-
LinkEntity entityLink = query.AddLink("entity", "extensionofrecordid", "entityid");
550-
entityLink.LinkCriteria.AddCondition("extensionofrecordid", ConditionOperator.Equal, tableEntityId);
558+
559+
LinkEntity entityLink = query.AddLink(
560+
"entity",
561+
"extensionofrecordid",
562+
"entityid");
563+
564+
entityLink.LinkCriteria.AddCondition(
565+
"extensionofrecordid",
566+
ConditionOperator.Equal,
567+
tableEntityId);
551568

552569
EntityCollection recyclebinconfigs = service.RetrieveMultiple(query);
553570

@@ -587,16 +604,16 @@ Use this `Disable-RecycleBinForTable` PowerShell function to disable the recycle
587604
function Disable-RecycleBinForTable {
588605
param(
589606
[Parameter(Mandatory)]
590-
[string]$tableLogicalName
607+
[guid]$tableId
591608
)
592609
593-
$query = "?`$filter=extensionofrecordid/name eq '"
594-
$query += $tableLogicalName
595-
$query += "'&`$select=recyclebinconfigid"
610+
$query = "?`$filter=_extensionofrecordid_value eq "
611+
$query += $tableId
612+
$query += "&`$select=recyclebinconfigid"
596613
597614
$recyclebinconfigs = (Get-Records `
598-
-setName 'recyclebinconfigs' `
599-
-query $query).value
615+
-setName 'recyclebinconfigs' `
616+
-query $query).value
600617
601618
if ($recyclebinconfigs.Count -eq 1) {
602619
$recyclebinconfigId = $recyclebinconfigs[0].recyclebinconfigid
@@ -605,12 +622,12 @@ function Disable-RecycleBinForTable {
605622
-setName 'recyclebinconfigs' `
606623
-id $recyclebinconfigId `
607624
-body @{
608-
'statecode' = 1
609-
'statuscode' = 2
610-
} | Out-Null
625+
'statecode' = 1
626+
'statuscode' = 2
627+
} | Out-Null
611628
}
612629
else {
613-
Write-Host "Recycle bin configuration for table '$tableLogicalName' not found."
630+
Write-Host "Recycle bin configuration for table $tableId not found."
614631
}
615632
}
616633
```
@@ -652,11 +669,12 @@ If you have this kind of custom business logic, then Dataverse doesn't know abou
652669

653670
> [!IMPORTANT]
654671
> Be careful about the context when you register plug-in steps for the `Restore` message. The record being restored will not be available in the `PreOperation` stage. If related records need to be created, use the `PostOperation` stage. [Learn more about plug-in stages](event-framework.md#event-execution-pipeline).
672+
>
655673
> The [InputParameters](understand-the-data-context.md#inputparameters) and [OutputParameters](understand-the-data-context.md#outputparameters) of the `Restore` message are similar to `Create` message, so plug-ins written to be registered for the `Create` message can be re-used for the `Restore` message with fewer changes.
656674
657675
## Tables not currently supported for Recycle Bin
658676

659-
The following tables are the result of the query found in [Detect which tables don't have recycle bin enabled](#detect-which-tables-dont-have-recycle-bin-enabled) in May of 2024 when the preview of this feature started.
677+
The following tables are the result of the query found in [Detect which tables don't have recycle bin enabled](#detect-which-tables-dont-have-recycle-bin-enabled) in May of 2024 when the preview of this feature started. [Private tables](entities.md#private-tables) are not included in this list.
660678

661679
:::row:::
662680
:::column:::

0 commit comments

Comments
 (0)