I'm trying to delete public groups and I run into the below:

MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object:

public static void deleteGroup(String groupId) {

        List<Group> groups = [ SELECT Id FROM Group WHERE Id = :groupId ];

        if (Test.isRunningTest()) {
            System.runAs(new User(Id = Userinfo.getUserId())) {
                delete groups;
        } else {
             delete groups;


Refer: http://www.tgerm.com/2012/04/mixeddmloperation-dml-operation-on.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.