We are not using the default 'qualify' procedure for a lead. Instead, there is a plugin that does the process, i.e. qualify the lead and create an opportunity and account using a QualifyLeadRequest. In addition to that, some additional information needs to be transferred from the lead to custom field in the opportunity. Here is what the code does (it's cut down to the most relevant parts)
qualifyRequest = new QualifyLeadRequest();
qualifyRequest.LeadId = new EntityReference(Lead.EntityLogicalName, lead.Id);
qualifyRequest.Status = new OptionSetValue(3); //3 = qualified.
qualifyResponse = (QualifyLeadResponse)service.Execute(qualifyRequest);
foreach(EntityReference eRef in qualifyResponse.CreatedEntities) {
if (eRef.LogicalName == Opportunity.EntityLogicalName) {
using (XrmServiceContext xrm = new XrmServiceContext(service)) {
opportunity = xrm.OpportunitySet.Where(o => o.Id == eRef.Id).FirstOrDefault<Opportunity>();
opportunity.new_BusinessPhone = lead.Address1_Telephone1;
xrm.UpdateObject(opportunity);
xrm.SaveChanges();
}
}
}
The whole code shown here is being executed successfully including the UpdateObject and SaveChanges, meaning it did not throw any exceptions. However, new_BusinessPhone on the newly created opportunity is empty.
What I would expect to happen is that:
1) Opportunity is being created
2) Opportunity is being updated. Note that I am RETRIEVING the opportunity that was created in step 1), i.e. it already exists.
However, it looks like that if the update of the opportunity happens during the same stage when it has been created, any changes are being ignored (without any errors). Is this correct? I could fix this by creating another plugin that is triggered when an opportunity is being created but I would much prefer if I could set the custom fields of the opportunity while it is being created.