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
MoDiggityMoDiggity 

Variable is not visible?

How come the variable is not visible?  It seems like the { set; } doesn't do anything without the presence of get; in that block.  Here's the code.

global with sharing class AppTrackerController {
                 
    public boolean accessError { set; }

    global AppTrackerController(ApexPages.StandardController stdController) 
    {
        accessError = false;
    }

}


Avidev9Avidev9
Without the get the page can't see the variable.
When you write {!accessError} the page tries to pull the data and since you don't have the get method it is not able to do so and throwing the error.
AshlekhAshlekh
Hi

You can use below code, It will not give you compile error,

global with sharing class AppTrackerController {
                 
    public boolean accessError { set; }

    global AppTrackerController(ApexPages.StandardController stdController) 
    {
       this.accessError = false;
    }

}
I tried your code in vairous mode any find the this soluiton.


IF it helps you than please mark it as a solution and ENJOY APEX
MoDiggityMoDiggity
Sorry I wasn't more clear...  The issue was a compile error when trying to save this file, not an error when trying to save a file that uses these properties.  Turns out the answer was more simple than I thought:

Simply changing:

public boolean accessError { set; }
to

public boolean accessError;

Fixed the problem.  I don't know that I fully understand why, but it works now.  Thanks for your help guys!
James LoghryJames Loghry
Like Avidev9 stated, you removed the "getter" from your variable.  Thus, any code that tried to read accessError from Apex or Visualforce, would not able to get or in otherwords see accessError.  By changing it to public boolean accessError, you're allowing apex to use default getter and setter methods.  Another way you could write it is:

public boolean accessError {get; set;}

Furthermore, if you wanted to encapsulate the variable and only allow accessError to be set in your class, then you could do something like:

public boolean accessError {get; private set;}