/// <summary> /// Create a Service Lead /// </summary> /// <param name="ownerPartyId"></param> /// <param name="orgExternalRef"></param> /// <param name="contactExternalRef"></param> /// <param name="name"></param> /// <returns></returns> public long? CreateServiceLead(long? ownerPartyId, long? orgExternalRef, long? contactExternalRef, string name) { ILeadService service = LeadService.GetService(); LeadModel model = new LeadModel(); model.Name = name; if (orgExternalRef != null) { model.CustomerId = (long)orgExternalRef; model.CustomerIdSpecified = true; } model.OwnerId = (long)ownerPartyId; model.OwnerIdSpecified = true; model.PrimaryContactId = (long)contactExternalRef; model.PrimaryContactIdSpecified = true; LeadModel result = service.CreateServiceLead(model); if (result != null && result.LeadId != null) { return result.LeadId; } return null; }
/// <summary> /// Create a ServiceLead in OSC /// </summary> /// <param name="leadModel">LeadModel</param> /// <returns></returns> public LeadModel CreateServiceLead(LeadModel leadModel) { LeadModel resultModel = null; try { if (leadModel != null) { ServiceLead lead = new ServiceLead(); lead.Name = leadModel.Name; lead.CustomerId = leadModel.CustomerId; lead.CustomerIdSpecified = leadModel.CustomerIdSpecified; lead.PrimaryContactId = leadModel.PrimaryContactId; lead.PrimaryContactIdSpecified = leadModel.PrimaryContactIdSpecified; lead.OwnerId = leadModel.OwnerId; lead.OwnerIdSpecified = leadModel.OwnerIdSpecified; if (!OSCCommonUtil.ValidateCurrentSiteName()) { resultModel = new LeadModel(); resultModel.LeadId = OSCOpportunitiesCommon.DefaultOpportunitySalesLeadID; return resultModel; } ServiceLead result = _leadService._leadClient.createLead(lead); resultModel = new LeadModel(); resultModel.LeadId = result.LeadId; } } catch (Exception exception) { _logger.Debug("Error occured while creating lead. Lead Not Created in Sales Cloud. Exception: " + exception.StackTrace); MessageBox.Show(OSCExceptionMessages.LeadOpportunityCannotBeCreated, OSCExceptionMessages.LeadNotCreatedTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } return resultModel; }