Hello,
I need delete Plugin code when parent record delete child record should also be delete
*This post is locked for comments
Hello,
I need delete Plugin code when parent record delete child record should also be delete
*This post is locked for comments
Could you share the code that you have been tried ?
you want to delete all the contacts when account is deleted?
or
You want to delete only primary contact?
thanks for suggestion but i need plugin code when account is delete related contact also delete in account entity have contact lookup primary contact from there i get guid of contact but its not going to delete error showing given key is not exit.............................
This is example code how i update the parent records when child records is deleted. You can change the "Update" message with "Delete".
public void Execute(IServiceProvider serviceprovider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceprovider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) { //If Delete, you should use "entityReference". Not Entity EntityReference entityreference = (EntityReference)context.InputParameters["Target"]; if (context.MessageName == "Delete") { Entity ent = service.Retrieve(entityreference.LogicalName, entityreference.Id, new ColumnSet("new_productname")); // Product Name is a Look Up Field That Contain the name of product which i want to update the quantity. var productname = ent.GetAttributeValue<EntityReference>("new_productname"); if (productname != null) { // Getting quantity field from child entity Entity product = service.Retrieve(productname.LogicalName, productname.Id, new ColumnSet("new_jumlahunit")); // Update the quantity on child entity var number = product.GetAttributeValue<Decimal>("new_jumlahunit"); var sisaunit = number + 1; product.Attributes["new_jumlahunit"] = sisaunit; service.Update(product); } } }
You want to delete the child records on certain conditions or delete all the time?
If you want to do it all the time, then you can set the relationship behavior as such.
Please refer the following:
https://community.dynamics.com/crm/b/crminogic/archive/2009/12/28/crm-relationship-behavior
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156