Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Qualify Lead, does not want to create an account but create contact and associate lead with existing account

Posted on by Microsoft Employee

with the below code i am able to qualify the lead record and associate it with existing account but not able to create contact.

var qualifylead = new QualifyLeadRequest
{
OpportunityCurrencyId = currencyId,
CreateOpportunity = true,
OpportunityCustomerId = new EntityReference(Account.LogicalName, (Guid)a.Attributes["accountid"]),
LeadId = new EntityReference(Lead.LogicalName, guid),
Status = new OptionSetValue(3)
};

With the below code i am able to qualify the lead record and create the contact record but not able to associate it with existing account using OpportunityCustomerId.

var qualifylead = new QualifyLeadRequest
{
OpportunityCurrencyId = currencyId,
CreateOpportunity = true,
CreateContact = true,
OpportunityCustomerId = new EntityReference(Account.LogicalName, (Guid)a.Attributes["accountid"]),
LeadId = new EntityReference(Lead.LogicalName, guid),
Status = new OptionSetValue(3)
};

create contact and associate lead with existing account.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Qualify Lead, does not want to create an account but create contact and associate lead with existing account

    Thanks alot,

    it works

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Qualify Lead, does not want to create an account but create contact and associate lead with existing account

    Hi,

    Please try this code to set the existing account

    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

               {

                   // Obtain the target entity from the input parameters.

                   Entity entity = (Entity)context.InputParameters["Target"];

                   try

                   {

                       //get the lead name in variable

                       string leadname = entity.Attributes["name"].ToString();

                       QueryExpression getAccount = new QueryExpression()

                       {

                           EntityName = "account",

                           Criteria = {

                                      Conditions =

                                      {

                                       new ConditionExpression("name",ConditionOperator.Equal,leadname),

                                      }

                                  }

                       };

                       EntityCollection retrieveAccount = service.RetrieveMultiple(getAccount);

                       if (retrieveAccount.Entities.Count > 0)

                       {

                           var qualifylead = new QualifyLeadRequest

                           {

                               CreateOpportunity = true,

                               CreateContact = true,

                               LeadId = new EntityReference("lead", entity.Id),

                               //Status = new OptionSetValue((int)lead_statuscode.Qualified)

                           };

                           var qualifyIntoAccountContactRes =

                           (QualifyLeadResponse)service.Execute(qualifylead);

                       }

                       entity.Attributes["parentaccountid"] = new EntityReference("account", retrieveAccount.Entities[0].Id);

                       service.Update(entity);

                   }

                   catch (Exception ex)

                   {

                       throw new InvalidPluginExecutionException("An error occurred in the FollowupPlugin plug-in.", ex);

                   }

               }

    Thanks

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans