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.
I'm running into a similar issue, the difference is that is NOT on a test methods, so, i cannot use runAs there.
ReplyDeleteI want to simply assign a queue to a record and i'm getting:
DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Lead, original object: QueueSobject: []
My code is this:
Group grp = new Group(Name='Queue',Type='Queue');
insert grp;
QueueSobject mappingObject = new QueueSobject(QueueId = grp.Id, SobjectType = 'Lead');
insert mappingObject;
Lead lead = new Lead(LastName = 'testLastName',company='test', OwnerId = grp.Id);
insert lead;
Thanks in advance.
Hi Jota,
ReplyDeleteAs you are performing DML operations on Setup(Group, QueueSobject) and non-setup object(Lead) in the same context, that's why you are getting this exception.
You can do one thing. You can call a future method from here and put your logic for lead DML in that. By doing this your context will be get changed.
Thank you! This helped greatly!
ReplyDeleteI am trying like this . still I am getting same kind error . not sure why it's coming
ReplyDeleteGroup grp = new Group(Name='testgrp',Email = 'testing@testing.com',DeveloperName='TestDeveloper',Type='Queue');
Insert grp;
QueueSobject MapObject = new QueueSobject(QueueId=grp.Id,SobjectType='Case');
Insert MapObject;
RecordType rType2 = [Select r.Name, r.DeveloperName From RecordType r where r.DeveloperName = 'Technical_Request'];
caseRec2 = new Case(RecordTypeID = rType2.id, Project__c = proj2.ID,Partner_Owner__c = portalUsr.id,Private_Project__c = 'Yes',Product__c = pro1.id,OwnerId = grp.Id,Partner_CC_IDs__c = portalUsr.id,CC_IDs__c = portalUsr.id);
İsmetpaşa
ReplyDeleteKnidos
Sanayi
İhsaniye
Bostanlı
UR5GF
Gümüşhane
ReplyDeleteKaraman
Kocaeli
Sakarya
Samsun
N3ENE
elazığ
ReplyDeletegümüşhane
kilis
siirt
sakarya
NBBDTY
ankara evden eve nakliyat
ReplyDeletemalatya evden eve nakliyat
antep evden eve nakliyat
giresun evden eve nakliyat
kayseri evden eve nakliyat
D03
EBE09
ReplyDeleteTunceli Evden Eve Nakliyat
Tekirdağ Lojistik
Karabük Evden Eve Nakliyat
Yozgat Lojistik
İzmir Parça Eşya Taşıma
C770B
ReplyDeleteKırıkkale Lojistik
Kars Parça Eşya Taşıma
Hatay Parça Eşya Taşıma
Yozgat Parça Eşya Taşıma
Afyon Evden Eve Nakliyat
D662D
ReplyDeleteBinance Güvenilir mi
Çorum Evden Eve Nakliyat
Silivri Parke Ustası
Düzce Evden Eve Nakliyat
Silivri Evden Eve Nakliyat
BD36E
ReplyDeletesarms
Gümüşhane Evden Eve Nakliyat
Çerkezköy Çatı Ustası
order dianabol methandienone
buy testosterone propionat
Yozgat Evden Eve Nakliyat
steroid cycles for sale
Çerkezköy Evden Eve Nakliyat
Ardahan Evden Eve Nakliyat
1A368
ReplyDeleteWabi Coin Hangi Borsada
Kocaeli Lojistik
Mardin Lojistik
Bolu Evden Eve Nakliyat
Isparta Lojistik
Bitcoin Kazanma
Aksaray Şehir İçi Nakliyat
Çerkezköy Cam Balkon
Sivas Parça Eşya Taşıma