+ Start a Discussion
babloo123babloo123 

Mixed DML error -Using future method but getting error

Hi I have a scenario where the contact has a checkbox called IS user active which has to be updated as and when user becomes inactive to false.

I wrote a trigger to do it showed me a mixed DML error and wrote the below code using future method as well now I am getting another error. Need some help on this

Trigger.

trigger Checkuseractive on User (after update) {

    user u=[select id,Isactive,contactid from user where id=:trigger.new[0].id];
    Id cid=u.ContactId;
if(trigger.new[0].IsActive=='false') 
{
    contactactivecheckboxclass.updatecnt(cid);
}
    
}

Future Method

public class contactactivecheckboxclass {
@future
    public static void Updatecnt(id x)
    contact c=[select Is_user_Active__c from Contact where id=:x];
    c.Is_User_Active__c=false;
    update c;
}

Error : Unexpected token :Contact on class line 4
Best Answer chosen by babloo123
John PipkinJohn Pipkin
You need curly braclets for your class method:
 
public class contactactivecheckboxclass {
@future
    public static void Updatecnt(id x){
        contact c=[select Is_user_Active__c from Contact where id=:x];
        c.Is_User_Active__c=false;
        update c;
    }
}

 

All Answers

John PipkinJohn Pipkin
You need curly braclets for your class method:
 
public class contactactivecheckboxclass {
@future
    public static void Updatecnt(id x){
        contact c=[select Is_user_Active__c from Contact where id=:x];
        c.Is_User_Active__c=false;
        update c;
    }
}

 
This was selected as the best answer
babloo123babloo123
Thanks a lot John The issue resolved.