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:

1 Answer 1

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


You must log in to answer this question.

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