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

Define & Insert Queues in Apex Triggers & Test Classes?


A Newbie question I'm sure, but...


What is the proper method to define and insert a Queue via an Apex Trigger or Test Class?

I'm good with standard & custom sObjects and the like, but I've not been able to find any clear documentation for inserting queues.


I found the metadata reference, but I'm not sure it applies to Apex:


When I use a statement like this:


Queue myQueue = new queue(email=queEmail,name=queName,fullName=queFullName,queueSobject=Case);


I get this error:


Error: Compile Error: Entity 'Queue' not accessible in version 25.0 at line 2 column 8


this is line 2


public class caseUpdateShadowUser_Test


So, can someone tell me what I've missed, or simply provide or direct me to a clear explanation of how to define and insert a Queue via a Trigger or Test Class?







Best Answer chosen by Admin (Salesforce Developers) 

It's a two step process:


            Group g1 = new Group(Name='group name', type='Queue');
            insert g1;
            QueuesObject q1 = new QueueSObject(QueueID =, SobjectType = 'Lead');
            insert q1;

Good luck