0

I am designing an empty VF page which has a controller which has a constructor which is being used to update values on user record but whenever I try to save the page it says Constructor is not visible.

This is my controller

public with sharing class reactivateUser {
    reactivateUser(){
        String userId= UserInfo.getUserId();
        User currentUser = [select lmscons__CFS_Status__c from user where id =: userid];
        currentUser.lmscons__CFS_Status__c = 'Active';
        update currentUser;    
   }
}

This is my VF page

 <apex:page controller="reactivateUser">
 <div> Your account was deactivated due to inactivity.You will be redirected to next page after reactivation now.
 </div>
 </apex:page>

Exact error message

Constructor is not visible: [reactivateUser]<init>(): Markup

3

There are two points. First you need to make it public. Second you can't make DML in constructor so create a method and put your DML there and call that method from your page's action attribute.

Class

public with sharing class reactivateUser {
    public reactivateUser(){

   }
   public void reactivateUserMethod(){
        String userId= UserInfo.getUserId();
        User currentUser = [select lmscons__CFS_Status__c from user where id =: userid];
        currentUser.lmscons__CFS_Status__c = 'Active';
        update currentUser;    
   }
}

VF Page

<apex:page controller="reactivateUser" action="{!reactivateUserMethod}">
 <div> Your account was deactivated due to inactivity.You will be redirected to next page after reactivation now.
 </div>
 </apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.