I have a trigger on a Contact object and when I try to update a User record in this trigger I get the following exception:
"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"
Trigger code:
trigger UpdateContactTrigger on Contact (after update) {
User u = [SELECT Id, IsActive FROM User WHERE IsActive = true];
u.IsActive = false;
update u;
}
How can I avoid this error while updating User record's fields from a Contact trigger?