Quantcast
Channel: Forum CRM Deployment
Viewing all articles
Browse latest Browse all 997

Can you tell CRM to not fire a plugin for a given SDK call?

$
0
0

I thought I saw an example of how to tell CRM not to fire a plugin when running some custom code. I have a web service that fires off every hour and syncs data between CRM and a legacy database. When this runs, CRM seems to get overwhelemed and the plugins will eventually crash. So if I can programmatically tell CRM that when I execute the SDK command, do not fire off any plugins, that would avoid the issue.

I can tell the issue is the plugin, as if I disable it I do not get the error.  If I enable the plugin, it runs about 10K of records before it crashes, then the plugin crashes with a "sandbox not available error", then it seems to recover and start working again for another 10K of records.

So it seems that maybe CRM cannot handle the volume of updates/creates I am pushing (10K in about 5 minutes) and eventually errors.  The error it throws is not within my custom code, but the default .Net code you use to access the local context.  I have commented my custom code so that all it does is hit the plugin code and does nothing.  The errors still occurs. 

I've included the code below, but removed the code that it never gets to.  The error seems to occur when accessing the localContext.  But remember it works fine for 10K of records, crashes, then works fine again for another 10K records before crashing again.

Any thoughts or suggestion are much appreciated.   

namespace DHI.EntityCustomizations.Plugins
{
    using System;
    using System.ServiceModel;
    using EntityCustomizations.Plugins;
    using Microsoft.Xrm.Sdk;

    /// <summary>
    /// PostContactUpdate Plugin.
    /// Fires when the following attributes are updated:
    /// All Attributes
    /// </summary>    
    public class PostContactUpdate : Plugin
    {

        private CrmServices _service;

        /// <summary>
        /// Initializes a new instance of the <see cref="PostContactUpdate"/> class.
        /// </summary>
        public PostContactUpdate()
            : base(typeof(PostContactUpdate))
        {
            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "contact", new Action<LocalPluginContext>(ExecutePostContactUpdate)));
        }

        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostContactUpdate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            // Obtain the execution context from the service provider.UpdateCreateEmpowerContact
            IOrganizationService orgService = localContext.OrganizationService;
            IPluginExecutionContext context = localContext.PluginExecutionContext;
            _service = new CrmServices(orgService); // Initialize the service class.
// It will never get here. The error seems to occur in the lines above.
        }
    }
}


Jon Gregory Rothlander




Viewing all articles
Browse latest Browse all 997

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>