function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DavserDavser 

Test Method Case with Queue Owner

Hey All,
Getting an error in a test method when trying to set a queue as a case owner. The code looks like:
Code:
Account testAcc = new Account(Name='TestAcc',AccountNumber='12345');
insert testAcc;
Contact testCont = new Contact(LastName='Testcontact',AccountId=testAcc.Id);
insert testCont;
Group testGroup = new Group(Name='TestingQueue',Type='Queue');
insert testGroup;
Case retCase = new Case(AccountId=testAcc.Id, ContactId=testCont.Id, Description='A sample description', Severity__c='Critical', Status='Assistance Required', Subject='Test subject',OwnerId=testGroup.Id);
insert retCase;

 
but this throws the error:
Error:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OPERATION, Queue not associated with this SObject type

 Is there a reason this error is happening? When i hardcode an existing queue id as the ownerid I do not get this error!
 
Thanks in advance for any help at all
Dave
Vijay RautVijay Raut
Hi Dave,

Apex doesnot allow DML operation on setup objects (like Group, Profile, Role,....) inside testmethod. Hence your Group Insert in failing in testmethod.

Thanks,
V.R.