Dynamics CRM: detecting cascade delete in the plugins

By | June 14, 2016

If you have a plugin that runs on “delete”, and if you need to detect whether that’s part of a “cascade delete” (in which case you might not want to update some sort of summary information on the parent entity), here is how it can be done:

if (context.ParentContext == null || context.ParentContext.MessageName == “Delete” && context.ParentContext.PrimaryEntityName != “{PARENT_ENTITY_NAME}”)


//Your “delete” processing goes here


In some cases, you might just want to know that it’s part of a cascade delete without really checking for the specific parent entity name, in which case you might have a slightly different condition:

if (context.ParentContext == null || context.ParentContext.MessageName == “Delete” && context.ParentContext.PrimaryEntityName != context.PrimaryEntityName)

To illustrate the difference, let’s imagine you have an entity with many different lookup fields, yet all those lookup relationships are configured to “cascade all” for the delete operation. In that case, “delete” can be cascaded from different parent entities, and, depending on how you want to handle it, you might either need to know what that parent entities is (first condition above), or you might just be interested to know that it is a cascade delete(second condition).


Leave a Reply

Your email address will not be published. Required fields are marked *