Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

c#plugin to pass compititor from lead to account

Posted on by 15

Hi everyone I am new to CRM
I am want to know how to write a c#plugin when the lead qualify it is creating an account,

when I add a competitor to the lead, now if I qualify the lead I want to pass the competitor to the newly created account...

please help me!

  • RE: c#plugin to pass compititor from lead to account

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    namespace ITV

    {

       public class Itvitaly : IPlugin

       {

           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;

                       contextplugin.InputParameters["CreateAccount"] = true;

                       contextplugin.InputParameters["CreateContact"] = true;

                   }

               }

               catch (InvalidPluginExecutionException ex)

               {

                   throw new InvalidPluginExecutionException(ex.Message);

               }

               catch (Exception ex)

               {

                   throw new InvalidPluginExecutionException(ex.Message);

               }

           }

       }

    }

    thanks for your help but I am very confused this plugin I wrote to avoid creating opportunity when the lead is qualified

    how to get the related lead of newly created account and how to write the query to retrieve multiple competitors ,, thanks in advance , it will means a lot me if anyone helps to me

  • Verified answer
    Saad Kabarousse Profile Picture
    Saad Kabarousse 732 on at
    RE: c#plugin to pass compititor from lead to account

    Hello,

    You will have to proceed this way:

    1- Create a plugin OnPostOperation of create of Account

    2- Get the Lead that it's associated to your newly Created Account

    3- Get list of Competitors associated to the Lead.

    4- Associate the Competitors to  your newly Created Account.

    These Operation can be done with the following requests:

    2- Retrieve to get the Lead.

    3- Retrieve Multiple to get List of Competitors

    4- AssociateRequest to Associate Competitors to your Account

    You can use this link to see how to create a Plugin

    carldesouza.com/.../

    Please Mark as Veirified if it helped You :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans