web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

c#plugin to pass compititor from lead to account

(0) ShareShare
ReportReport
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!

I have the same question (0)
  • Verified answer
    Saad Kabarousse Profile Picture
    734 on at

    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 :)

  • Preetham Holenarasipuradeveraju Profile Picture
    15 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans