Dynamics CRM: Writing Unit Tests

As Dynamics CRM developers, is a pain to write unit tests for Plugins/Jscript/Custom Actions/Custom Workflows and most of the time, unit tests are just ignored.

Recently discovered a framework called Fake XRM Easy which can be found here, that makes unit testing in Dynamics CRM effortless.

Thanks to Jordi for this awesome framework.


Dynamics CRM 2016: Generic SQL Error searching for contacts


In CRM when searching for a contact via quick find or on a lookup control, a Generic SQL error pop’s up.


A column was recently added to the quick find view to enable users to search on that field when searching for contacts. This introduced the Generic SQL error behavior which required tracing to find the real issue.

Tracing Log

Exception when executing query: WITH __QuickFind__ as (select top 10001 [ContactId] from (

SELECT “contact0”.[Key] AS [ContactId] FROM ContainsTable([ContactBase], ( EMailAddress2, MobilePhone, LastName, FullName, FirstName, EMailAddress1), ‘(((“test*” OR FORMSOF(FREETEXT, “test”))) OR (“*test”))’) AS “contact0”) as [__QuickFindInternal__])

Exception: System.Data.SqlClient.SqlException (0x80131904): Full-text table or indexed view has more than one LCID among its full-text indexed columns.

The Fix

Log on the SQL server, open the Dynamics CRM database and follow this steps:

  • Navigate to the Contact table
  • Left click on the table
  • Navigate to Full-text index
  • Click on properties
  • Select Columns
    •  Make sure the Language for Word Breaker is the same.

sql1 sql2


CRM 2015: How to register a plugin for a Global Custom Action using CRM Toolkit

Scenario: I have a custom action that is registered against global (None), but I want to create a plugin that will execute my logic when the action is invoked. These are the steps I took to register the plugin using the CRM toolkit.

  • Create a plugin against any entity in the system, I prefer to use the system user entity. Select the normal plugin setting i.e. Message, Pipeline Stage etc.
  1. 1Then modify the plugin created in step 1, first update the message to the name of your custom action, secondly update the name of the entity to an empty string




  • Open the RegisterFile of the CrmPackage and update the plugin created in step 1. Firstly update the MessageName to your custom action name, secondly remove the PrimaryEntityName=”systemuser” tag completely and save the file.





  • Rebuild your project, deploy and test.

CRM 2015 Plugins – Avoiding Infinite Loops

This has been a pain for quite some time and have been using (localContext.PluginExecutionContext.Depth > 1) to avoid the infinite plugin loop. BUT this also creates another problem when the plugin suppose to execute either during data import or when using a workflow to create/update.

Problem SOLVED by using localContext.SharedVariables in the plugin. First you need a function to check if the SharedVariables exist before executing your plugin logic, if it does not exist then add it. The trick is to check the SharedVariables in the parent context of the context. See below code:

protected void ExecutePostCaseUpdate(LocalPluginContext localContext)
if (localContext == null)
throw new ArgumentNullException(“localContext”);

if (!CheckRecursionIndicator(localContext.PluginExecutionContext, “ExecutePostCaseUpdateIndicator”)) return;
var updateCase = ((Entity)localContext.PluginExecutionContext.InputParameters[“Target”]).ToEntity();

// TODO: Implement your custom Plug-in business logic.
updateCase.Title = “Plugin Shared Viarable Test”;

/// Check plugin loop recursion

private bool CheckRecursionIndicator(IPluginExecutionContext context, string recursionIndicator)
if (!context.SharedVariables.Contains(recursionIndicator))
while (context.ParentContext != null)
if (context.ParentContext.SharedVariables.Contains(recursionIndicator))
return false;
context = context.ParentContext;

context.SharedVariables.Add(recursionIndicator, (Object)true);
return true;

Microsoft Dynamics CRM 2015 :Release Preview Guide

Click Here to view the release guide.

Workflow Elements by Aiden Kaskela

Microsoft Business Solutions MVP (CRM), Contractor, Evangelist


Real Experiences from Analyzing, Architecting, developing and working with Dynamics CRM, Dynamics 365 and sometimes .net

Mark Margolis's Blog

It's about Software, CRM, Product Development and sometimes Food.


Gareth Tucker on Microsoft Dynamics CRM

Donna Edwards

Sharing my Journey with Microsoft Dynamics 365 Business Solutions

The WordPress.com Blog

The latest news on WordPress.com and the WordPress community.