Hi i have a problem cuz I'm trying do sth like below:
this method has adnotation AuraEnabled
Contact contact = getContact((Id)contactId);
contact.Inactive__c = true;
User user = getUserByContactId(contactId);
user.IsActive = true;
update user;
update contact;
And I'm receiving error like :
MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: Contact: []
… what should i do ?
Best Answer
You can perform DML operations on more than one type of sObject in a single class using the following process:
You can’t use the following sObjects with other sObjects when performing DML operations in the same transaction.
You can only insert and update a group in a transaction with other sObjects. Other DML operations aren’t allowed.
You can update a user in a transaction with other sObjects in Apex code saved using Salesforce API version 15.0 and later if the user isn’t included in an Lightning Sync configuration (either active or inactive) and the following fields are not updated:
More information here:-