If I reference a single ActivityId it works fine.
The following error is shown "An error occured while processing this request" at line xrm.SaveChanges();
What am I doing wrong?
protected void ModifyEmails_Click(object sender, EventArgs e) { var xrm = new XrmServiceContext("Xrm"); var GetEmails = xrm.EmailSet .Where(c => c.StateCode.Equals(1)) //.Where(c => c.ActivityId.Equals("e85d7026-0167-e311-b548-3c4a92dbd83d")) .Where(c => c.DirectionCode.Equals(true)) .Where(c => c.mp_contactid2.Equals(null)) .Take(5) .ToList(); foreach (Email email in GetEmails) { EntityCollection Recipients = email.GetAttributeValue<EntityCollection>("to"); ActivityParty ap = Recipients[0].ToEntity<ActivityParty>(); email.mp_contactid2 = new EntityReference(Contact.EntityLogicalName, ap.PartyId.Id); xrm.UpdateObject(email); }; xrm.SaveChanges(); }