---
schema_version: "1"
id: bcaf66ab185f192e77ddf69e4678184405a87050c2aed8396b17b3cd8e98efc6
title: sObjects That Can’t Be Used Together in DML Operations
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_dml_non_mix_sobjects.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 46e552aa8453fea3272875e8fc48a8f5a96188f4e498e00b24a7e0d3baa49385
description: DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on non-setup sObjects in the same transaction. This restriction exists because some sObjects affect the user’s access to records in the org. You must insert or update these types of sObjects in a different transaction to prevent operations from happening with incorrect access-level permissions. For example, you can’t update an account and a user role in a single transaction.
---
# sObjects That Can’t Be Used Together in DML Operations

DML operations on certain sObjects, sometimes referred to as setup objects, can’t be mixed with DML on non-setup sObjects in the same transaction. This restriction exists because some sObjects affect the user’s access to records in the org. You must insert or update these types of sObjects in a different transaction to prevent operations from happening with incorrect access-level permissions. For example, you can’t update an account and a user role in a single transaction.

Don’t include more than one of these sObjects in the same transaction when performing DML operations or when using the Metadata API.

These sObjects also can't be used with the [@IsTest (IsParallel=true)](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_isTest.htm#isParallelTrue) annotation. Split such operations into separate transactions.

![Note](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/images/icon_note.png)

#### Note

This list includes sObjects that cannot be used together in the same DML transaction, but is not an exhaustive list.

- AuthSession
- ContentWorkspace
- FieldPermissions
- ForecastingShare
- Group
    
    You can only insert and update a group in a transaction with other sObjects. Other DML operations aren’t allowed.
- GroupMember
    
    ![Note](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/images/icon_note.png)
    
    #### Note
    
    With legacy Apex code saved using Salesforce API version 14.0 and earlier, you can insert and update a group member with other sObjects in the same transaction.
- ObjectPermissions
- ObjectTerritory2AssignmentRule
- ObjectTerritory2AssignmentRuleItem
- PermissionSet
- PermissionSetAssignment
- QueueSObject
- RuleTerritory2Association
- SetupEntityAccess
- Territory
- Territory2
- Territory2Model
- User
    
    You can insert a user in a transaction with other sObjects in Apex code saved using Salesforce API version 14.0 and earlier.
    
    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.
    
    You can update a user in a transaction with other sObjects in Apex code saved using Salesforce API version 14.0 and earlier
    
    You can update a user in a transaction with other sObjects in Apex code saved using Salesforce API version 15.0 and later when the user isn’t included in a [Lightning Sync](https://help.salesforce.com/articleView?id=lightning_sync_admin_overview.htm&language=en_US) or [Einstein Activity Capture](https://help.salesforce.com/s/articleView?id=sales.einstein_sales_aac.htm&type=5&language=en_US) configuration (either active or inactive) and the following fields aren’t updated:
    
    - UserRoleId
    - IsActive
    - ForecastEnabled
    - IsPortalEnabled
    - Username
    - ProfileId
- UserPackageLicense
- UserRole
- UserTerritory
- UserTerritory2Association

If you're using a Visualforce page with a custom controller, you can't mix sObject types with any of these special sObjects within a single request or action. However, you can perform DML operations on these different types of sObjects in subsequent requests. For example, you can create an account with a save button, and then create a user with a non-null role with a submit button.

You can perform DML operations on more than one type of sObject in a single class using the following process:

1. Create a method that performs a DML operation on one type of sObject.
2. Create a second method that uses the [future](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_future.htm "Use the Future annotation to identify methods that run asynchronously. A future method runs when Salesforce has available resources.") annotation to manipulate a second sObject type.

This process is demonstrated in the example in the next section.

## Example: Using a Future Method to Perform Mixed DML Operations

This example shows how to perform mixed DML operations by using a future method to perform a DML operation on the User object.

public with sharing class MixedDMLFuture {
    public static void useFutureMethod() {
        // First DML operation
        Account a = new Account(Name='Acme');
        insert as system a;
        
        // This next operation (insert a user with a role) 
        // can't be mixed with the previous insert unless 
        // it is within a future method. 
        // Call future method to insert a user with a role.
        Util.insertUserWithRole(
            'mruiz@awcomputing.com', 'mruiz', 
            'mruiz@awcomputing.com', 'Ruiz');        
    }
}

public with sharing class Util {
    @future
    public static void insertUserWithRole(
        String uname, String al, String em, String lname) {

        Profile p = \[SELECT Id FROM Profile WHERE Name='Standard User' WITH SYSTEM\_MODE\];
        UserRole r = \[SELECT Id FROM UserRole WHERE Name='COO' WITH SYSTEM\_MODE\];
        // Create new user with a non-null user role ID 
        User u = new User(alias = al, email=em, 
            emailencodingkey='UTF-8', lastname=lname, 
            languagelocalekey='en\_US', 
            localesidkey='en\_US', profileid = p.Id, userroleid = r.Id,
            timezonesidkey='America/Los\_Angeles', 
            username=uname);
        insert as system u;
    }
}

- **[Mixed DML Operations in Test Methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects_test_methods.htm)**  
    Test methods allow for performing mixed Data Manipulation Language (DML) operations that include both setup sObjects and other sObjects if the code that performs the DML operations is enclosed within System.runAs method blocks. You can also perform DML in an asynchronous job that your test method calls. These techniques enable you, for example, to create a user with a role and other sObjects in the same test.