throw an exception while trying to delete a record RRS feed

  • Question

  • Hi,

    I want to throw an exception error while trying to delete a record in ms crm 2013 using plugin by registering a delete message step in sdk and giving pre-operation...

    I ahve tried using a basic plugin but it is not working.. Can anyone suggest me a basic plugin which fires an error when we are trying to delete a record in accounts entity...........

    • Edited by Amy.4 Tuesday, April 1, 2014 9:24 AM
    Tuesday, April 1, 2014 9:24 AM


  • Hi Amy,

    Something like this should get you started. Hope this helps.

    using System;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;
    namespace CRMPlugin
        public class account: IPlugin
            public void Execute(IServiceProvider serviceProvider)
                IPluginExecutionContext context = (IPluginExecutionContext)
                if (context.MessageName.ToLower() == "delete" && context.PrimaryEntityName.ToLower() == "account")
                    throw new InvalidPluginExecutionException("Deletion of Account is not allowed");

    Eric UNG [Senior Analyst Programmer :: Sydney, Australia]

    • Proposed as answer by HIMBAPModerator Wednesday, April 2, 2014 12:00 AM
    • Marked as answer by Amy.4 Thursday, April 10, 2014 11:25 AM
    Tuesday, April 1, 2014 9:52 AM