Text Scroll
You must welcome, Thank you for visiting my blog.
Search This Blog
Monday, July 6, 2020
prevented Lead from creating Opportunity and Account while qualify lead to opportunity
prevented Lead from creating Opportunity and Account
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext contextPlugin = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(contextPlugin.UserId);
if (contextPlugin.MessageName != "QualifyLead") return;
OptionSetValue LeadStatecode = new OptionSetValue();
OptionSetValue LeadStatuscode = new OptionSetValue();
EntityReference LeadRef = null;
try
{
LeadRef = (EntityReference)contextPlugin.InputParameters["LeadId"];
Entity Lead = service.Retrieve("lead", LeadRef.Id, new ColumnSet(true));
if (LeadRef.LogicalName != "lead")
{ return; }
LeadStatecode = Lead.GetAttributeValue<OptionSetValue>("statecode");
LeadStatuscode = Lead.GetAttributeValue<OptionSetValue>("statuscode");
if (LeadStatecode.Value == 0 && LeadStatuscode.Value == 1)
{
contextPlugin.InputParameters["CreateOpportunity"] = false; // set to true by default
contextPlugin.InputParameters["CreateAccount"] = false; // set to true by default
}
}
catch (InvalidPluginExecutionException ex)
{throw new InvalidPluginExecutionException(ex.Message);}
catch (Exception ex)
{throw new InvalidPluginExecutionException(ex.Message);}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment