0

I HAVE WRITTEN THE BELOW CODE BUT IT IS NOT THROWING THE MIXEDDMLEXCEPTION AND I DON'T UNDERSTAND WHY.

public class April22Task2 {
    public static void createUserAndAccount()
    {
            //inserting a non-setup Object.
        Account a = new Account();
        a.name='DmlException Account'; 
        a.AccountNumber='42012121';
        insert a;

        
        //inserting a setup Object
        User u=new User();
        u.lastname='Dr DMlException Resolver';
        u.Alias='Rolv';
        u.Email='[email protected]';
        u.username='[email protected]';
        u.CommunityNickname='Doctor12121';
        u.TimeZoneSidKey='Asia/Kolkata';
        u.LocaleSidKey='en_IN';
        u.EmailEncodingKey='UTF-8';
        u.ProfileId='00eGB000003sLhrYAE';
        u.LanguageLocaleKey='en_US';
        insert u;

    }
}

1 Answer 1

1

As we can read in sObjects That Can’t Be Used Together in DML Operations

You can insert a user in a transaction with other sObjects in Apex code saved using Salesforce API version 15.0 and later when UserRoleId is specified as null.

Your UserRoleId is null.

Try to specify it or use another SObject Type mentioned in sObjects That Can’t Be Used Together in DML Operations.

You must log in to answer this question.

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