Qualify a Lead in C#

Typically, when we want to deactivate a record in a plugin or a workflow, we turn to SetStateRequest. Qualifying a Lead isn't quite as straightforward. If you've qualified a Lead through the CRM interface, you'll know that:
  • An Opportunity is created from the originating Lead.
  • You can select whether to create a Contact or Account from the originating Lead.
QualifyLeadRequest in the Microsoft.Crm.Sdk.Messages namespace provides us with a class which allows us to specify all of these options and more programatically.

The code snippet below creates a new QualifyLeadRequest, populating all of it's required properties.

Replace all of my empty new EntityReference() objects with valid EntityReferences (which are instantiated by passing an entity name and an ID). Refer to the Microsoft documentation for information on other optional parameters which you can use.

The request is executed and its response stored in the qualifyLeadResponse:

The most interesting property of the response object is CreatedEntities. See the Microsoft documentation for information on other properties stored in the QualifyLeadResponse.

CreatedEntities contains a collection of EntityReferences, one for each entity created when qualifying the Lead. To get the Contact that was created, for example, iterate through the collection and query the LogicalName of each EntityReference:

2 comments:

  1. Great Artical..!
    How to Qualify a Lead - Qualifying a business lead online requires a lot of skill and finesse. In this blog, we reveal a few tricks of the trade to procure the right kind of lead for your to boost your business.
    How to Qualify a Lead

    ReplyDelete
  2. Need help on this...
    I am setting all booleans values to true. I want to create all three records.
    But the parameter "OpportunityCustomerId" is required. Since I am creating the account and contact on qualify itself, how could i give the entityreference to that?

    ReplyDelete