cookya
cookya

Reputation: 3307

Creating a connection record fails: "An unexpected error occurred"

I'm trying to create a connection between a queue item record and a record of a custom entity called "queue_item_deletion_log". The code is executed on a synchronous pre-operation plugin with a Delete message on queueitem.

I'm getting an OrganizationServiceFault exception: "An unexpected error occurred." with no further information.

This is my code:

try
{
    Entity entConnection = new Entity("connection");
    entConnection["record1id"] = new EntityReference("queue_item_deletion_log", deletionLogId);
    entConnection["record2id"] = entity.ToEntityReference();
    crmService.Create(entConnection);
}
catch (Exception ex)
{
   // - write to log -
   return;
}

Any help would be appreciated.

Upvotes: 0

Views: 541

Answers (1)

Alex
Alex

Reputation: 23310

You are missing record1roleid and record2roleid attributes, both of them are of EntityReference type and specify the connection roles.

Your code should end up being:

try
{
    Entity entConnection = new Entity("connection");
    entConnection["record1id"] = new EntityReference("queue_item_deletion_log", deletionLogId);
    entConnection["record1roleid"] = /*entity ref. to connection role here*/
    entConnection["record2id"] = entity.ToEntityReference();
    entConnection["record2roleid"] = /*entity ref. to connection role here*/
    crmService.Create(entConnection);
}
catch (Exception ex)
{
   // - write to log -
   return;
}

Upvotes: 1

Related Questions