Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I update the owner id of a Contact using LINQ?

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?

like image 979
Daryl Avatar asked Oct 12 '11 20:10

Daryl


1 Answers

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);
like image 164
ccellar Avatar answered Oct 16 '22 17:10

ccellar