Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Can rollup fields be used in a query for a bulk delete? Reliably? (Bulk Delete deleted things it should not have)

Posted on by 496

I'm asking because we had a Bulk Delete Job set up that would delete certain types of accounts but ONLY if Opportunity Count = 0.

For years it ran fine but last Friday, it went rogue and deleted 5 accounts that had opportunities (and Opportunity Count clearly shows numbers greater than 0 when looked at in a form).  Of course, that resulted in 30+ opportunities being deleted as well, and all this on our production system.

I'm looking at the Bulk Delete query and I can clearly see Opportunity Count is Equal to 0 in the definition.

I'm wondering if this is something funky with roll-up fields.

Microsoft is RCA'ing it and we're restoring the data manually by recreating these opportunities from a backup system but I mostly want to prevent this from ever happening again.

  • ShannonCRM Profile Picture
    ShannonCRM 496 on at
    RE: Can rollup fields be used in a query for a bulk delete? Reliably? (Bulk Delete deleted things it should not have)

    I can see that being possible, except in this case, the Opportunities had been created up to 2 years in the past.  And if I restore to 30 minutes prior to the delete, the Opportunity Count rollup field is already rolled up to more than 0.  

    I guess I will have to wait and see what Microsoft says in their telemetry investigation.  I think this could be a bug - just need it confirmed.

    I will still mark your answer as correct as it will probably help others.

  • Verified answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,319 on at
    RE: Can rollup fields be used in a query for a bulk delete? Reliably? (Bulk Delete deleted things it should not have)

    Hi,

    Thank you for your query.

    Roll-up fields are refreshed (calculated) every 12 hours (by default). However, you can change this configuration.

    It is possible in your scenario, that opportunities are created but roll-up field is not refreshed when bulk delete job executes.

    To fix this, you have to make sure Rollup fields are refreshed before Bulk Delete executes.

    You can do this in following ways:

    • Increase frequency of Roll-up fields refresh, however this decreases your system's performance:

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/265143/d365-v9-rollup-frequency/748884#:~:text=The%20default%20recurrence%20is%201,All%20Rollup%20Field%20Calculation%20Jobs%22

    • Refresh the calculated field on account programmatically using CalculateRollupFieldRequest. You can register a plugin to execute CalculateRollupFieldRequest on account when an opportunity is created:

    http://www.msdynamicsblog.com/programatically-recalculating-rollup-fields-through-a-plugin-in-crm/

    https://pradipwebmaster.wordpress.com/tag/calculaterollupfieldrequest-in-crm/

    • Also, instead of using a condition within bulk delete, you can create a plugin for account entity which executes on delete and checks for related opportunity counts. If count is >0, throw InvalidOperationException so the account is not deleted.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans