You need to sign in to do that
Don't have an account?
Mahatma Vijay
Error during test!
I did a test run on this class and it gave me an error. Can someone guide me as to how I can run this test successfully?
Errors:
System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): QueueSobject, original object: Assignment_Group__c: []
Stack Trace:
Class.F8_Test_AssignmentGroupQueue.F8_Test_AssignmentGroupQueue: line 32, column 1
@isTest private class F8_Test_AssignmentGroupQueue { static testMethod void F8_Test_AssignmentGroupQueue() { Assignment_Group__c objAssignmentGroup = new Assignment_Group__c(Name='Test_AG'); insert objAssignmentGroup; Group g1 = new Group(Name='group name', type='Queue'); insert g1; QueuesObject q1 = new QueueSObject(QueueID = g1.id, SobjectType = 'Assignment_Group__c'); insert q1; Group g2 = new Group(Name='group name2', type='Queue'); insert g2; QueuesObject q2 = new QueueSObject(QueueID = g2.id, SobjectType = 'Assignment_Group__c'); insert q2; Group g3 = new Group(Name='group name3', type='Queue'); insert g3; QueuesObject q3 = new QueueSObject(QueueID = g3.id, SobjectType = 'Assignment_Group__c'); insert q3; Assignment_Group_Queue__c objAssignmentGroupQueue = new Assignment_Group_Queue__c(Name = 'group name', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true); insert objAssignmentGroupQueue; Assignment_Group_Queue__c objAssignmentGroupQueue2 = new Assignment_Group_Queue__c(Name = 'group name2', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true); insert objAssignmentGroupQueue2; objAssignmentGroupQueue.Active__c = 'False'; update objAssignmentGroupQueue; objAssignmentGroupQueue.Name = 'group name3'; update objAssignmentGroupQueue; try{ objAssignmentGroupQueue.Name = 'group name2'; update objAssignmentGroupQueue; } catch(Exception ex){ system.debug('## Exception is ::' + ex); } Assignment_Group_Queue__c objAssignmentGroupQueue3 = new Assignment_Group_Queue__c(); try{ objAssignmentGroupQueue3 = new Assignment_Group_Queue__c(Name = 'group name2', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true); insert objAssignmentGroupQueue3; } catch(Exception ex){ system.debug('## Exception is ::' + ex); System.assertEquals(objAssignmentGroupQueue3.Id, null); } try{ objAssignmentGroupQueue3 = new Assignment_Group_Queue__c(Name = 'group name23', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true); insert objAssignmentGroupQueue3; } catch(Exception ex){ system.debug('## Exception is ::' + ex); System.assertEquals(objAssignmentGroupQueue3.Id, null); } try{ objAssignmentGroupQueue.Name = 'group name23'; update objAssignmentGroupQueue; } catch(Exception ex){ system.debug('## Exception is ::' + ex); } } }
Errors:
System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): QueueSobject, original object: Assignment_Group__c: []
Stack Trace:
Class.F8_Test_AssignmentGroupQueue.F8_Test_AssignmentGroupQueue: line 32, column 1
Thanks Mahesh for doing the best in helping me.
All Answers
You are getting this error because your test is creating a group and queue, which are setup objects, and then attempting to create a Custom Object which is an application object.
You can solve this by creating a user and executing the rest of the test as that user via the System.runAs method.
Below is the modified code:
Please do let me know if it helps you.
Regards,
Mahesh
Also go through the below links:
https://developer.salesforce.com/forums/?id=906F00000008ypaIAA
https://developer.salesforce.com/forums/?id=906F00000008z0DIAQ
http://salesforce.stackexchange.com/questions/66046/mixed-dml-operation-dml-operation-on-setup-object-is-not-permitted-after-you-ha
http://salesforce.stackexchange.com/questions/72591/mixed-dml-operation-dml-operation-on-setup-object-is-not-permitted
http://salesforce.stackexchange.com/questions/13318/error-mixed-dml-operation-on-setup-and-non-setup-objects
Please do let me know if it helps you.
Regards,
Mahesh
Thank you so much for the help. I tried the code but I got this error. I'm new to Salesforce Development and can you help with this following error as well?
Error: Compile Error: Variable does not exist: u at line 58 column 22
System.runAs(u)
to
System.runAs(user)
Regards,
Mahesh
Still getting same errors
Errors:
System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): QueueSobject, original object: Assignment_Group__c: []
Stack Trace:
Class.F8_Test_AssignmentGroupQueue.F8_Test_AssignmentGroupQueue: line 32, column 1
Regards,
Mahesh
I'm still getting the same error message.
Thanks Mahesh for doing the best in helping me.