web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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)

(0) ShareShare
ReportReport
Posted on by 502

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.

I have the same question (0)
  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at

    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.
  • ShannonCRM Profile Picture
    502 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans