function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Activate User through trigger

I have one Custom object and with lookup of User object, When we save this custom object first it will check the related user is active or not. if not active then it has to activate the user and save record.
One @Future method is allready written for User object.

Here is the error which i am getting:
first error: 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: ClientReview__c: []

Here is my method which i wrote in class:
 Public void ToActiveateUser(List<ClientReview__c> clientReviewList)
      List<ClientReview__c> alertReviewList = new List<ClientReview__c>();
        Map<String,RepCode__c> repCodeMap=this.getRepCodeMap(clientReviewList);
        List<Id> AdvisorUsers = new List<Id>();
        for(ClientReview__c review:clientReviewList){
            String repCode=review.ClientRepCode__c;
            if(repCode !='')
                RepCode__c rc=repCodeMap.get(repCode);
                    String ownerId=rc.Advisor__r.Advisor_User__pc;
                    if(ownerId != '')
         List<User> advisorUser = [Select Id,IsActive FROM User WHERE Id IN:AdvisorUsers];
         List<User> updateuser = new List<user>();
         for( User usr: advisorUser)
           if(usr.IsActive == false)
               usr.IsActive = true;
            update updateuser; 

And i am calling this method in Trigger:

Trigger Supervision_Sharing on ClientReview__c (after insert) {
    SupervisionOperations so=new SupervisionOperations();   
Arunkumar RArunkumar R
Hi Pral,

As you know, You cannot insert or update setup and non setup object at same time. You definately need to write @future method to update your records.

please follow the below links, it might be helpful,