[Dataverse] Use Truncate for CRM Integration Record cleanup during environment copy - #10207
[Dataverse] Use Truncate for CRM Integration Record cleanup during environment copy#10207Onat Buyukakkus (onbuyuka) wants to merge 3 commits into
Conversation
…vironment copy Refactor CleanCDSIntegration to bulk-delete CRM Integration Records with Record.Truncate, falling back to DeleteAll when truncate is unsupported. This avoids row-by-row deletion timeouts during Production-to-Sandbox environment copy. ChangeCompany scoping and the OnBeforeCleanCRMIntegrationRecords hook are preserved; TableKey.DisableAll now runs only on the DeleteAll fallback path. Adds tests for current-company cleanup, ChangeCompany cleanup, the Truncate-supported assumption, and the DeleteAll fallback. Fixes AB#646451 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ebca36ed-fe9f-40bc-b671-1e534fa84af1
|
CleanCDSIntegrationFallsBackToDeleteAllWhenTruncateUnsupported only asserts that CRM Integration Record is empty after cleanup. That same assertion also passes on the normal Truncate() success path, so if the manual subscriber stops making Truncate() unsupported, this test would still pass without ever exercising the new DeleteAll fallback branch it claims to cover. Add a precondition (e.g. assert CRMIntegrationRecord.Truncate() returns false while the subscriber is bound) or another fallback-specific signal that proves the DeleteAll() path was actually taken. Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4 |
|
CleanCDSIntegrationCleansCompanySelectedViaChangeCompany verifies only CRM Integration Record rows in the selected company. It never seeds or asserts company-scoped CDS Connection Setup / CRM Connection Setup, so a regression where ChangeCompany is applied to CRM Integration Record but not to the setup tables would still pass this new test. Seed setup rows in the alternate company and assert both setup tables are removed there. Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4 |
Place the test subscriber in Microsoft.Integration.Dataverse (same namespace as the objects it references) so no using directive is needed and the analyzer namespace warning is cleared. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ebca36ed-fe9f-40bc-b671-1e534fa84af1
Record.Truncate is treated as a Commit by the test framework, so tests marked [TransactionModel(AutoRollback)] that call Truncate (directly or via CleanCDSIntegration) fail to build with 'Tests cannot call the Commit function if TransactionModel property is set to AutoRollback'. Switch the four environment-cleanup tests to AutoCommit; Initialize -> ResetEnvironment already clears CRM Integration Records between tests, so there is no cross-test pollution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ebca36ed-fe9f-40bc-b671-1e534fa84af1
What & why
Production-to-Sandbox environment copy runs
CleanCDSIntegration(codeunit 7201 CDS Integration Impl.), which deleted every CRM Integration Record row withDeleteAll(). On large coupling tables this row-by-row delete runs for a long time or times out (ICM 51000000014610, repair item 610313).This change switches the cleanup to a bulk
Record.Truncate()and falls back toDeleteAllonly when truncate is unsupported (e.g. a delete-event subscriber or a security filter on the table).ChangeCompanyscoping and theOnBeforeCleanCRMIntegrationRecordshook are preserved, andTableKey.DisableAllnow runs only on the slow fallback path where it is actually needed.Linked work
Fixes AB#646451
How I validated this
What I tested and the outcome
CleanCDSIntegrationproduce zero diagnostics.CDSIntegrationMgtTest(+ a small manual subscriberCDSCleanupTestSubscribers):CleanCDSIntegrationTruncatesCRMIntegrationRecordsForCurrentCompany— current-company cleanup removes records and connection setup.TruncateIsSupportedForCRMIntegrationRecordTable— guards the assumption thatTruncateactually engages for this table (itsOnDeletetrigger does not block truncate; without this, a silent regression toDeleteAllwould pass the other tests).CleanCDSIntegrationCleansCompanySelectedViaChangeCompany— cleans a company selected viaChangeCompanywhile preserving the current company.CleanCDSIntegrationFallsBackToDeleteAllWhenTruncateUnsupported— a bound delete-event subscriber forces truncate off; records are still removed via the fallback.Risk & compatibility
OnBeforeCleanCRMIntegrationRecordssubscribers that disable cleanup keep working.Truncateskips the table'sOnDeletetrigger (Sales Header -> Sales Line coupling cascade), which is harmless here because the whole table is being cleared during environment copy.