Saturday 19 November 2016

Get the Created Records When Lead is Qualified in Dynamic CRM Using Plug-in

Lead is Qualified in Dynamic CRM
Description:


In this example we explain how to get the last created records when Lead is Qualified in Dynamic CRM using plug-in.or how to fetch or retrieve the created records when Lead is Qualified in Dynamic CRM using plug-in.

Sometimes you have requirement like when lead is qualified then you need some custom logic to work then at this time this scenario is very useful for you.
So below is the plugin code to retrieve or fetch the created record when Lead is Qualified in Dynamic CRM

Plugin In Code :

// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

// Getting the service from the Organisation Service.
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

// Get the qualified lead.
EntityReference leadid = (EntityReference)context.InputParameters["LeadId"];
Entity lead = service.Retrieve("lead", leadid.Id, new ColumnSet(true));

foreach (EntityReference created in (IEnumerable<object>)context.OutputParameters["CreatedEntities"])
{
    //Check if Account record is created when lead qualified.
    if (created.LogicalName == "account")
    {
        Entity account = service.Retrieve("account", created.Id, new ColumnSet(true));
    }
    
    //Check if Contact record is created when lead qualified.
    if (created.LogicalName == "contact")
    {
        Entity contact = service.Retrieve("contact", created.Id, new ColumnSet(true));
    }

    //Check if Opportunity record is created when lead qualified.
    if (created.LogicalName == "opportunity")
    {
        Entity opportunity = service.Retrieve("opportunity", created.Id, new ColumnSet(true));
    }
}

.
This entry was posted in :

0 comments:

Post a Comment