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
c_r_carvalhoc_r_carvalho 

How to set two sbjects to a queue by apex?


When I create a queue on browser, it's possible to configure two sbjects or more in a queue, but i can't to do the same thing in apex class.
How can I accomplished this?

For instance:

QueueSobject qs = new QueueSobject(SobjectType='MyObject1__c;MyObject2__c', Name='My queue test');
Database.insert( qs );

This is what i want or something like that.

tks,
Best Answer chosen by c_r_carvalho
pconpcon
You just need to insert two of them
Queue myQueue = [
     select Id
     from Group
     where Name = 'My queue test' and
          Type = 'Queue'
];

List<QueueSobject> qs = new List<QueueSobject>();
qs.add(new QueueSobject (
     SobjectType='MyObject1__c'
     QueueId = myQueue.Id
);
qs.add(new QueueSobject (
     SobjectType='MyObject2__c'
     QueueId = myQueue.Id
);
Database.insert( qs );