Basically subj:

Some of my test classes pass when I run them in MavensMate, but fail when I run them in Apex Test Execution in the org itself.


MavensMate testclass

Apex Test Execution:

Apex Test Execution testclass

And just because I think it might be useful for a good answer, the error(same error for all 5 methods) that I get in Apex Test Execution is:

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): GroupMember, original object: Account: []

So the question is:
What could be the reason of such a different behaviour?

  • Seems related to salesforce.stackexchange.com/questions/54301/… Commented Nov 17, 2015 at 14:24
  • @Eystornt thanks for your comment, but the question is a bit different. I want to know the reason why the same test class fails in the browser, but passes in MavensMate
    – Novarg
    Commented Nov 17, 2015 at 15:39
  • hey @Novarg after run test class in mavensmate. have you got code coverage?
    – Ratan Paul
    Commented Nov 23, 2015 at 10:15
  • Hi @Ratan. Yes, I do see the code coverage in MavensMate
    – Novarg
    Commented Nov 23, 2015 at 10:16
  • 1
    In this case I think it can be either a MavensMate issue or you have outdated version of your test class on your local pc. Because I have the same error (Mixed DML Operation) in MavensMate (v7.0.0-beta.1 on Mac) and SF UI if my test tries to update Setup and non-Setup objects. And this is correct behaviour.
    – steals
    Commented Nov 23, 2015 at 16:13

1 Answer 1


This sort of thing has been going on since the Summer '08 release. See How to avoid MIXED_DML_OPERATION error in Salesforce tests that create Users.

Essentially, there are certain types of sObjects that you can't perform DML operations on in a test case and then proceed to modify other types of sObject. See sObjects That Cannot Be Used Together in DML Operations

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

  • GroupMember
    You can only insert and update a group member in a transaction with other sObjects in Apex code saved using Salesforce API version 14.0 and earlier.

The typical solution to this is to use System.runAs to separate the sObject types that can't have DML performed together.

Other Uses of runAs

You can also use the runAs method to perform mixed DML operations in your test by enclosing the DML operations within the runAs block. In this way, you bypass the mixed DML error that is otherwise returned when inserting or updating setup objects together with other sObjects.

Why is MavensMate behaving differently than the Salesforce UI?

Again, this oddity comes back to how the test is being run. I encountered it in 2011 when Eclipse gave different test results to the Salesforce UI. External tools like MavensMate and the Force.com IDE rely on using the public APIs to perform test runs.

In the case of MavemsMate, it currently runs the test cases via the mm executable with the test operation (possibly unit_test). Maybe if you can read node.js fluently you can find which specific API call is being made.

Anyway, one or more of the Salesforce APIs that can be used to run test cases produce a different result to the standard Salesforce UI. There are several options to running test cases, such as the Tooling API, Metadata API or the Apex API. Then there are SOAP and REST versions available.

This may be as specific as the API version that the calls are being made against. The Salesforce UI, including the developer console, will be using current API version. Whereas the external tooling may be several releases behind.

You must log in to answer this question.

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