Dynamics 365 Raise Error in Plugin

Leave a comment

To raise an error in the plugin code, we use InvalidPluginExecutionException.

For example:

throw new InvalidPluginExecutionException("Plugin has run. Code will stop executing.");

The code runs in the Execute function of the plugin code. For example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query; 
 
namespace Carl.AssociateDisassociate
{
    public class AssociateDisassociate : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            throw new InvalidPluginExecutionException("Plugin has run. Code will stop executing.");
        }
    }
}

The code will display the error and stop executing:

If you register the code on the Pre-Operation it will prevent the rest of the CRM code from running:

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, BI, Web, Cloud and Data Science.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

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