[SalesForce] Create queue and assign the queue to case owner

I want to create a queue first. then i have to assign the case owner to that particular queue. How to accomplish this ?

I am trying to create a queue using Apex

Group testGroup = new Group(Name='testgroup', Type='Queue');
insert testGroup;
QueuesObject testQueue = new QueueSObject(QueueID = testGroup.id, SObjectType = 'Case');
insert testQueue;

I am getting the error as

DML operation INSERT not allowed on Group

Provide me a solution please..

Thanks in advance

Best Answer

Are you doing other things as part of this code?

There are restrictions on what DML operations you can perform in the same context For example You can only insert and update a group in a transaction with other sObjects. Other DML operations are not allowed.

I find that I can run your code fragment provided without problem. So maybe you are doing something else in the code before this which is forbidden in combination with DML on the Group.

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_non_mix_sobjects.htm

Related Topic