0

Scenario -> Creation Contact share record and in the same transaction creating GroupMembers for one of groups related to custom object.

Throws -> Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): GroupMember, original object: ContactShare: []

As per doc Mixed DML only comes up when we we mix setup and non-setup objects in a transaction. So isn't both ContactShare and GroupMember setup objects?

I know how to fix this, but got confused with error message as I thought we can update multiple setup objects in one transaction.

1

GroupMember is the setup object, but ContactShare is not.

You can see the list of sObjects that cannot be used together in DML operations that I included below:

  • FieldPermissions
  • Group
  • GroupMember
  • ObjectPermissions
  • PermissionSet
  • PermissionSetAssignment
  • QueueSObject
  • ObjectTerritory2AssignmentRule
  • ObjectTerritory2AssignmentRuleItem
  • RuleTerritory2Association
  • SetupEntityAccess
  • Territory2
  • Territory2Model
  • UserTerritory2Association
  • User (couple exceptions for insert/update scenarios depending on fields updated)
  • UserRole
  • UserTerritory
  • Territory
  • Custom settings in Apex code saved using Salesforce API version 17.0 and earlier

Some of these have certain exception if you're using API 15 or earlier, but the documentation contains the specifics. For example, GroupMember could be in a DML operation in API 14 or earlier.

2
  • I checked the documentation (developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/…) but do not see these objects listed. Is there any other mechanism based on which one can identify setup/nonsetup objects? Thanks
    – Swetha
    Apr 1 at 6:58
  • 1
    The document linked in my answers is the clearest the I could find that I believe covers all when it comes to apex/DML. The Tooling API doc is more concerned about identifying setup objects accessible in the Tooling API which is why you see some objects not listed (GroupMember is not available in Tooling API). Apr 1 at 11:36

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.