User Story
As a Salesforce Administrator, I want to be able to create a new Queue with the name "Support Team C" i and associate it to Case, Task and Customer Objects in Apex so that I can better manage and organize my data.
Code
Group newGroup = new Group();
newGroup.Name = 'Support Team C';
newGroup.Type = 'Queue';
insert newGroup;
// Associate the queue with the Case object
List<QueueSobject> QueueSobjectList = new List<QueueSobject>();
List<String> SObjectNames = new List<String>();
SObjectNames.add('Case');
SObjectNames.add('Task');
SObjectNames.add('Customer');
for(String sObjectName : SObjectNames){
QueueSobject queueSobject = new QueueSobject();
queueSobject.QueueId = newGroup.Id;
queueSobject.SobjectType = sObjectName;
QueueSobjectList.add(queueSobject);
}
insert QueueSobjectList;