This exception come when we perform DML operation on standard/custom object and global objects(User, UserRole, Group, GroupMember, Permission Set, etc…) in same transaction.
To avoid this exception, we should perform DML operation on standard/custom object records in a different transaction.