I'm using CRM 2011, and attempting to update the OwnerId of contact using this code:
var crmContext = new CustomCrmContext(service);
var contact = crmContext.Contact.FirstOrDefault(c=>c.Id == id);
contact.OwnerId.Id= newOwnerId;
crmContext.UpdateObject(contact);
crmContext.SaveChanges();
I don't get any errors, however, the ownerId never updates in the database. I am able to update other attributes, but I'm just wondering if maybe the OwnerId is special and you have to use OrganizationRequest("Assign")? If so, where is this documented so I know what other attributes I cannot update?
The owner of a record cannot be modified with an update. You have to send a AssignRequest instead.
// Create the Request Object and Set the Request Object's Properties
var request = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName, _newOwnerId),
Target = new EntityReference(Account.EntityLogicalName, _accountId)
};
// Execute the Request
_service.Execute(request);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With