RE: How To Check in Plugin If a Lead Record Is Created by Email?
Hello Furkan,
you can check the parent context like the following:
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "lead")
{
Entity lead = entity;
if (context.ParentContext.ParentContext != null && context.ParentContext.ParentContext.PrimaryEntityName == "activitypointer")
{
tracingService.Trace("The lead was created by " + context.ParentContext.ParentContext.InputParameters["ActivityEntityName"].ToString());
}
}
}
}
Enabling the plugin trace in your org you can see that if you use Convert To inside Email, you will have something like:
