Hi All,
Once
Lead Gets Qualify, as per oob behavior it will automatically create opportunity,
contact and accounts.
As
per my logic whenever an opportunity gets created need to set created lead id
to custom opportunity field.
Plugin Step Creation:
Register Plugin as Asynchronously
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service =
serviceFactory.CreateOrganizationService(context.UserId);
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
EntityReference getLeadid = (EntityReference)context.InputParameters["LeadId"];
Entity lead = service.Retrieve("lead", leadid.Id, new ColumnSet(true));
foreach (EntityReference CreatedEntityFromLead
in ((IEnumerable)context.OutputParameters["CreatedEntities"]))
{
if (CreatedEntityFromLead.LogicalName
== "opportunity")
{
Entity entOpportunity = service.Retrieve("opportunity", CreatedEntityFromLead.Id,
new ColumnSet(true));
entOpportunity["new_customLookupid"] = erLookUpField;
service.Update(entOpportunity);
}
}
No comments:
Post a Comment