On Update of an <account> record, the plug-in must update a related record (new_port) having a one-to-one relationship with account through new_accountid.
The code below doesn't do it!
I debugged and the id parameter received by the method is correct.
Also, new_port was created as a custom Activity entity.
Any idea what am I doing wrong?
private static void UpdateAccountPort(IOrganizationService service, Guid id) { try { using (var crm = new XrmServiceContext(service)) { var account = crm.AccountSet.Where( a => a.AccountId == id).First(); var port = crm.new_portSet.Where( p => p.new_accountid.Equals(id)).First(); port.Subject = account.Name; port.new_territoryid = account.TerritoryId; port.new_relationshiptypecode = account.CustomerTypeCode.Value; port.new_accountorcontactownerid = account.OwnerId; crm.Attach(port); crm.UpdateObject(port); crm.SaveChanges(); } } catch (FaultException ex) { throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex); } }
Frank