public void ConvertLead()
{
SalesforceSession salesforceSession = SessionTest.GetActiveSession();
Lead lead = null;
LeadService leadService = null;
ContactService contactService = null;
Contact contact = null;
try
{
lead = new Lead();
lead.FirstName = "TerryJohn";
lead.LastName = "HumphrisSmith";
lead.Company = "HumphrisSmith Co";
lead.Status = "Closed - Converted";
leadService = new LeadService(salesforceSession);
SaveResult saveResult = leadService.Insert(lead);
Assert.IsTrue(saveResult.success);
// Lead will now have an Id
Assert.IsTrue(leadService.ValidEntityId(lead.Id));
LeadConvert leadConvert = new LeadConvert();
leadConvert.leadId = lead.Id;
leadConvert.overwriteLeadSource = false;
leadConvert.doNotCreateOpportunity = true;
leadConvert.convertedStatus = lead.Status;
leadConvert.sendNotificationEmail = false;
//leadConvert.contactId = contactId;
//leadConvert.accountId = accountId;
//leadConvert.opportunityName = opportunityName;
LeadConvertResult[] lcr = salesforceSession.Binding.convertLead(new LeadConvert[] { leadConvert });
for (int i = 0; i < lcr.Length; i++)
{
if (lcr[i].success)
{
Console.WriteLine("Conversion succeeded.\n");
LeadConvertResult result = lcr[i];
contactService = new ContactService(salesforceSession);
contact = contactService.GetByEntityId(result.contactId);
Assert.IsTrue(contactService.ValidEntityId(result.contactId));
}
else
{
Console.WriteLine("Failed: " + lcr[i].errors[0].message);
Assert.Fail();
}
}
}
finally
{
if (contactService != null && contact != null && contact.Id != null)
{
try { contactService.DeleteContact(contact); }
catch (Exception) { }
}
}
}
|