1

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

5
  • What exactly is the problem that you are having in creating a queue? Are you using the user interface (as an administrator) to do this? What error are you getting when you try to create the queue?
    – Doug B
    Commented May 19, 2015 at 10:47
  • 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
    – ram451
    Commented May 19, 2015 at 10:56
  • This code works for me. Which user profile is running the code? Portal users cannot create groups.
    – Doug B
    Commented May 19, 2015 at 11:05
  • No its not portal user.. Its normal user only
    – ram451
    Commented May 19, 2015 at 11:21
  • Please check if your user has correct permission or not. basically to create queue you need to have "Customize application" permission. If your user has this permission then probably you are doing other DML operation in same transaction i.e. you are updating/inserting/deleting Account or other object records along with creation of Queue. Commented Oct 7, 2017 at 6:40

2 Answers 2

1

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

0

The following sObjects can’t be used with other sObjects when performing DML operations in the same transaction:

  • Group
  • GroupMember
  • ObjectPermissions
  • PermissionSet
  • PermissionSetAssignment
  • QueueSObject
  • SetupEntityAccess
  • User

You can only insert and update a group in a transaction with other sObjects. Other DML operations are not allowed. You can only insert and update a group member in a transaction with other sObjects in Apex code saved using Salesforce.com API version 14.0 and earlier. Try executing them in 2 different transactions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .