ForceChallenges
ProblemsDailyNotesInterview
Sign in

Practice

All problemsSOQL practiceApex trigger challengesDaily challengeOpportunityTrigger.oldMapBefore UpdateBulkificationContactValidationGROUP BYSemi-JoinAccountBefore Insert

Interview questions

All questionsAdminAdministrationApexApex TriggerAsync ApexDevelopmentField ServiceField ServiceIntegrationLwc

By company

DeloitteSalesforceAccentureInfosysPwCCognizant

Learn

Study notes

ForceChallenges

AboutContact usPrivacy PolicyTerms of ServiceFor AI assistants (llms.txt)
© 2026 ForceChallenges · Salesforce SOQL & Apex trigger practice
Apex Trigger questions6 of 32
Apex TriggerMedium 1 min read

How do Mixed DML Errors happen in triggers (e.g., creating a User and an Account in the same transaction) and how do you resolve them?

Asked atDeloittePwCAccenture

Answer

Mixed DML error (MIXED_DML_OPERATION) occurs when setup objects (User, Group, GroupMember, PermissionSetAssignment, UserRole, etc.) and non-setup objects (Account, Contact, custom objects) are modified in the same transaction.

Solutions:

  • Move the setup-object DML (or the non-setup one) to a separate transaction using @future or Queueable Apex.
  • In tests, wrap one side in System.runAs().
apex
@future
public static void assignPermSet(Set<Id> userIds) { /* insert PermissionSetAssignment */ }
apex-triggertriggermixed-dmlasync
Practice SOQL & Apex
PreviousHow do Platform Events and Change Data Capture (CDC) triggers differ from standard SObject triggers?Next What happens if an unhandled exception occurs inside a trigger during a bulk DML operation (insert list vs Database.insert(list, false))?

More Apex Trigger questions

  • How do you write a test class to achieve 100% code coverage and meaningful assertions for bulk triggers (testing with 200+ records)?
  • How do you handle UNABLE_TO_LOCK_ROW errors triggered during high-volume updates on parent records?
  • Does with sharing or without sharing on a Trigger Handler class affect SOQL and DML executed from the trigger?
  • Under what user context do Apex Triggers run (System Mode vs User Mode)?
  • If a batch of 250 records is inserted via Data Loader, how many times does the trigger execute and how are governor limits shared?