Recently I experienced with a new exception , while I was creating a test class for one of mine functionality.
I looked for the solution on community and other places but couldn't find helpful.So I continued myself .
here is the case what I was looking for:
Create a lead whose owner should be a queue.
I started with this :
Group grp = new Group(Name='Queue',Type='Queue');
insert grp;
Lead lead = new Lead(LastName = 'testLastName',company='test', OwnerId = grp.Id);
insert lead;
but when I was running the class, result was with the exception :
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OPERATION, Queue not associated with this SObject type: []
Here is the solution to shoot this error:
There is an object named "QueueSobject".
Represents the mapping between a queue Group and the sObject types associated with the queue, including custom objects.
So whenever you want to have a group as an owner for a record , QueueSObject should be there to mapped that record with Group.
like:
Group grp = new Group(Name='Queue',Type='Queue');
insert grp;
QueueSobject mappingObject = new QueueSobject(QueueId = grp.Id, SobjectType = 'Lead');
System.runAs(new User(Id = UserInfo.getUserId()))
{insert mappingObject;}
Lead lead = new Lead(LastName = 'testLastName',company='test', OwnerId = grp.Id);
insert lead;
So try this whenever you are in same kind of trouble.
Queries/comments are invited.
I looked for the solution on community and other places but couldn't find helpful.So I continued myself .
here is the case what I was looking for:
Create a lead whose owner should be a queue.
I started with this :
Group grp = new Group(Name='Queue',Type='Queue');
insert grp;
Lead lead = new Lead(LastName = 'testLastName',company='test', OwnerId = grp.Id);
insert lead;
but when I was running the class, result was with the exception :
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OPERATION, Queue not associated with this SObject type: []
Here is the solution to shoot this error:
There is an object named "QueueSobject".
Represents the mapping between a queue Group and the sObject types associated with the queue, including custom objects.
So whenever you want to have a group as an owner for a record , QueueSObject should be there to mapped that record with Group.
like:
Group grp = new Group(Name='Queue',Type='Queue');
insert grp;
QueueSobject mappingObject = new QueueSobject(QueueId = grp.Id, SobjectType = 'Lead');
System.runAs(new User(Id = UserInfo.getUserId()))
{insert mappingObject;}
Lead lead = new Lead(LastName = 'testLastName',company='test', OwnerId = grp.Id);
insert lead;
So try this whenever you are in same kind of trouble.
Queries/comments are invited.