I am using a VF page for my 'Visualforce Tabs' Community Home page. I have a custom button on top of it which says: Instructions Reviewed. Clicking on it would take them to another page. And whenever the user logins again, the button should not be shown at all. How can I achieve this via code?

I think a checkbox on the User record can be used as a flag. As I am an administrator and very new to programming, I am not sure how to achieve this.


If you are trying to update a checkbox value whenever a user clicks on the button and based on that checkbox value, if you want to hide the button, this might work well:


<apex:commandButton action="{!updateFlag}" 
           value="Instructions Reviewed" />

Apex class:

public Boolean instructionsFlag {get; set;}
public User currentUser = [SELECT Checkbox__c FROM User WHERE Id =: UserInfo.getUserId()];

public EducationPageController(){
    instructionsFlag = currentUser.Checkbox__c;

public void updateFlag(){
        currentUser.Checkbox__c = TRUE;
        update currentUser;

Hope this helps.

  • 2
    oh, missed that user thing, kind of looks like my answer, but you fulfilled it :) – Basti Oct 13 '17 at 20:11

You need to use the rendered attribute on your button:

<apex:commandButton action="{!foo}" value="Review" rendered="{!NOT(reviewed)}"/>

Your Controller would need to define the variable reviewed:

Boolean reviewed{ get; set; }

// Constructor
public PageController() {
    reviewed = [SELECT Reviewed__c FROM YourObject__c WHERE Id = whatever].Reviewed__c;

I have no input about your controller's context so this is a more generic answer.

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.