Hi Andy,
At a glance seems like your problem is the plugin cant get until this stage:
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity target = (Entity)context.InputParameters["Target"];
========================================================
Can you try to put this exception inside your code:
try
{
context.InputParameters["CreateOpportunity"] = false; 
}
So will be:
try
{
throw new InvalidPluginExecutionException("tested here");
}
Then try to qualify your lead whether you hit this or not.
Andy, please also refer to this one:
ashwaniashwin.wordpress.com/.../modify-lead-qualification-process-in-microsoft-dynamics-crm-2013
I think it is because your target entity cant get the lead so it hit the "return" instead'
So you need to define the variable lead like this:
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
service = serviceFactory.CreateOrganizationService(context.UserId);
// Get the qualified lead
EntityReference leadid = (EntityReference)context.InputParameters["LeadId"];
Entity lead = service.Retrieve(leadid.LogicalName, leadid.Id, new ColumnSet(true));
Try this lead
Instead of using yours:
Entity target = (Entity)context.InputParameters["Target"];
==========================================================
public class LeadQualification : Plugin
{
public LeadQualification()
: base(typeof(LeadQualification))
{
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "QualifyLead", "lead", new Action<LocalPluginContext>(ExecuteLeadQualification)));
}
protected void ExecuteLeadQualification(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IPluginExecutionContext context = (IPluginExecutionContext)
localContext.ServiceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("LeadId") )
{
// Obtain the target entity from the input parameters.
//Entity target = (Entity)context.InputParameters["Target"];
//replace to:
Entity lead = service.Retrieve(leadid.LogicalName, leadid.Id, new ColumnSet(true));
//</snippetFollowupPlugin2>
// Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
if (lead.LogicalName != "lead")
return;
try
{
//expected it will hit this..
context.InputParameters["CreateOpportunity"] = false;
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
//EntityHelper.CreateLogOnCrm(localContext.OrganizationService, "An error occurred in comparing financial records.", ex, targetRef);
}
}
}
}
}
Hope this helps.
Thanks