function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Developer BaseDeveloper Base 

Test class does not trigger mixed DML error - why not?

Hey, I am studying for developer II cert and I ran into a peculiar thing.

my test class does NOT trigger mixed DML error, although I am inserting setup and non-setup objects. Why not? My code:
 
@isTest
public class UpdateAccountNameTest {
    @isTest
    public static void test1(){
        Profile prfl = [Select Id, Name from Profile where name ='System Administrator'];
        
        Account acc = new Account();
        acc.Name = 'test';
        insert acc;
        
        Custom_Object1__c a = new Custom_Object1__c();
        a.Name = 'testAccount';
        insert a;
        
        User usr2 = new User();
        usr2.LastName = 'setup1';
        usr2.Username = 'test1@test123.net';
        usr2.Email = 'tes1t@test123.net';
        usr2.Alias = 'Test1';
        usr2.CommunityNickname = 'Test1';
        usr2.TimeZoneSidKey = 'Europe/Prague';
        usr2.LocaleSidKey = 'cs_CZ';
        usr2.EmailEncodingKey = 'UTF-8';
        usr2.ProfileId = prfl.Id;
        usr2.LanguageLocaleKey = 'en_US';
        usr2.IsActive = true;
        insert usr2;     
    }
}

 
Best Answer chosen by Developer Base
Developer BaseDeveloper Base
So for some reason when creating a User record, if I do not create record with UserRoleId field, it wont trigger Mixed DML Error. That is the reason.