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
NJDeveloper019NJDeveloper019 

Test class with controller class variables not visible

I am building a test Class that will get me over the 75% hump that I need to deploy again to Production.  The problem seems to be that I need to access and set variables in my controller class to be able to go through the conditional statements of the methods in the controller class.  Most of these variables are private but a few are public variables.  For both sets of variables tho I continue to get a save error stating, "Variable is not visible".  Am I doing something incorrect here or can I not access these variables.  Some code below will hopefully help illustrate my issue.  Mind you I removed almost everything from the controller class because it is much too large to post here.

 

TEST CLASS

@isTest
private class searchTest {
   
    static testMethod void searchTest()
    {
        PageReference pageRef = Page.AdvancedSearch;
       
        Test.setCurrentPageReference(pageRef);
       
        searchController mySearchCon = new searchController();
       
        string s = null;
       
        s = mySearchCon.toggleVisibility();
        system.assertEquals(s, null);
       
        mySearchCon.criteriaVal = true;
        Boolean b = mySearchCon.getShowCriteria();
        system.assertEquals(b, true);

       
        List<SelectOption> l = mySearchCon.getUserList();
        system.assert(l.size() > 0);
       
        l = mySearchCon.getBusinessUnitList();
        system.assert(l.size() > 0);
       
        l = mySearchCon.getSearchChoice();
        system.assert(l.size() > 0);
       
        l = mySearchCon.getStateList();
        system.assert(l.size() > 0);
       
        l = mySearchCon.getJOStatusList();
        system.assert(l.size() > 0);
       
        l = mySearchCon.getSubmitStatusList();
        system.assert(l.size() > 0);
    }
   
}

 

CONTROLLER CLASS

public class searchController
{
    private List<User> users = new List<User>();
    private List<Business_Unit__c> units = new List<Business_Unit__c>();
    private List<Account> accountResults = new List<Account>();
    private List<Contact> contactResults = new List<Contact>();
    private List<Consultant__c> consultantResults = new List<Consultant__c>();
    private List<Job_Order__c> jobOrderResults = new List<Job_Order__c>();
    private List<Submit__c> submitResults = new List<Submit__c>();
    //private List<Location__c> state = new List<Location__c>();
    //private string[] unit = new string[]{};
    private List<String> unit = new List<String>{};
    private string user = null;
    private string searchType = null;
    private integer unitCount = 0;
    private string queryUnit = null;
    private string queryUser = null;
    private string querySearch = null;
    private string querySelect = null;
   
    //Account Search Variables
    private string accountName = null;
    private string accountId = null;
    private string city = null;
    private string state = null;
   
    //Contact Search Variables
    private string contactName = null;
    private string contactId = null;
    private string contactEmail = null;
   
    //Consultant Search Variables
    private string consultantName = null;
    private string consultantId = null;
    private string consultantHomeEmail = null;
    private string consultantWorkEmail = null;
    private string consultantResume = null;
   
    //Job Order Search Variables
    private string jobOrderId = null;
    private string jobOrderPositionTitle = null;
    private string jobOrderDescription = null;
    private string jobOrderStatus = null;
   
    //Submit Search Variables
    private string submitId = null;
    private string submitStatus = null;
   
    //AJAX variables
    boolean criteriaVal = false;
    boolean accountVal = false;
    boolean contactVal = false;
    boolean consultantVal = false;
    boolean jobOrderVal = false;
    boolean submitVal = false;
    boolean interviewVal = false;
    boolean resultsVal = false;
    boolean resultsTableVal = false;

 

    //Flags
    boolean unitFlag = false;
    boolean unitAllFlag = false;
    boolean userFlag = false;
    boolean userAllFlag = false;
    boolean searchFlag = false;
    boolean unitDisabledFlag = false;
   
    //Error variablea
    boolean noUnitUser = false;
    boolean noResults = false;
    boolean disabledUnit = false;

   

 

    public Boolean getShowCriteria()
    {
        return criteriaVal;
    }

}

 

 

ERROR
Save error: Variable is not visible: criteriaVal

wesnoltewesnolte

Hey

 

 You don't have any public variables, just one public getter. Try putting the access modifier 'public' in front of your varible declarations e.g.

 

 public boolean criteriaVal = false;

 

More info can be found here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_access_modifiers.htm?SearchType=Stem 

 

Cheers,

Wes 

NJDeveloper019NJDeveloper019
That isa good point as I forgot that without a type it is defaulted to private.  But even with public there I am still getting the same error.  The two classes are in the same project and I am assuming the same namespace so I believe they should be working.
NJDeveloper019NJDeveloper019
Is it not possible to set a public variable that resides in my searchController class from my test class without a property setup in the searchController class?  I cannot seem to set even public variables.
Walter@AdicioWalter@Adicio

Can you use something like this?

 

 

public boolean criteriaVal { get; set;} {criteriaVal=false;}

 

 

 

NJDeveloper019NJDeveloper019
That is my previous question.  I think I could set up a public property to allow me access to the public variable, but it seems un-necessary to me to build a list of properties for variables with the sole purpose of testing.  These properties would have no use to the actual application itself.
wesnoltewesnolte

Hmm.. this is something my co-worker and I were wondering the other day. What was the outcome? Does it only work with public properties?

 

Wes

NJDeveloper019NJDeveloper019

Now this is really bothering me now.  I removed the criteriaVal from the variable list and made it a public property instead.  I set it up an automatic property and it is clearly visible in my test class.  And it is still giving me the same error:

 

Save error: Variable is not visible: criteriaVal

 

This makes no sense to me and honestly it better start making sense soon because my computer and desk is moving ever closer to getting Hulk Smashed and left for dead.

 

CONTROLLER CLASS

public class searchController
{
    private List<User> users = new List<User>();
    private List<Business_Unit__c> units = new List<Business_Unit__c>();
    private List<Account> accountResults = new List<Account>();
    private List<Contact> contactResults = new List<Contact>();
    private List<Consultant__c> consultantResults = new List<Consultant__c>();
    private List<Job_Order__c> jobOrderResults = new List<Job_Order__c>();
    private List<Submit__c> submitResults = new List<Submit__c>();
    //private List<Location__c> state = new List<Location__c>();
    //private string[] unit = new string[]{};
    private List<String> unit = new List<String>{};
    private string user = null;
    private string searchType = null;
    private integer unitCount = 0;
    private string queryUnit = null;
    private string queryUser = null;
    private string querySearch = null;
    private string querySelect = null;
   
    //Account Search Variables
    private string accountName = null;
    private string accountId = null;
    private string city = null;
    private string state = null;
   
    //Contact Search Variables
    private string contactName = null;
    private string contactId = null;
    private string contactEmail = null;
   
    //Consultant Search Variables
    private string consultantName = null;
    private string consultantId = null;
    private string consultantHomeEmail = null;
    private string consultantWorkEmail = null;
    private string consultantResume = null;
   
    //Job Order Search Variables
    private string jobOrderId = null;
    private string jobOrderPositionTitle = null;
    private string jobOrderDescription = null;
    private string jobOrderStatus = null;
   
    //Submit Search Variables
    private string submitId = null;
    private string submitStatus = null;
   
    //AJAX variables
    //private boolean criteriaVal = false;
    public boolean accountVal = false;
    public boolean contactVal = false;
    public boolean consultantVal = false;
    public boolean jobOrderVal = false;
    public boolean submitVal = false;
    public boolean interviewVal = false;
    public boolean resultsVal = false;
    public boolean resultsTableVal = false;
   
    //Flags
    public boolean unitFlag = false;
    public boolean unitAllFlag = false;
    public boolean userFlag = false;
    public boolean userAllFlag = false;
    public boolean searchFlag = false;
    public boolean unitDisabledFlag = false;
   
    //Error variables
    public boolean noUnitUser = false;
    public boolean noResults = false;
    public boolean disabledUnit = false;   
   
    public Boolean criteriaVal { get; set; }

}

 

TEST CLASS

@isTest
private class searchTest {
   
    static testMethod void searchTest()
    {
        PageReference pageRef = Page.AdvancedSearch;
       
        Test.setCurrentPageReference(pageRef);
       
        searchController mySearchCon = new searchController();   

 

        Boolean b;

        mySearchCon.criteriaVal = true;
        b = mySearchCon.criteriaVal;
        system.assertEquals(b, true);
    }
   
}

Message Edited by NJDeveloper019 on 07-09-2009 07:50 AM
Message Edited by NJDeveloper019 on 07-09-2009 07:51 AM
wesnoltewesnolte

hmmm... something's amiss here. I've put all your code into my IDE and it works. Have you tried dumping this code into the classes via the browser? We've tried all the obvious things so now I'm just guessing..

 

Wes

NJDeveloper019NJDeveloper019

Wes,

 

Are you putting the Test Class as a class within the controller class?  Or is it a completely separate class in your IDE?

 

Ralph

wesnoltewesnolte

I am putting it into a completely seperate class. Are you not even able to save the test class or is it a runtime error? If you view the classes in the browser are they the same as in the IDE? It seems that somehting is holding onto some old code.

 

Wes

NJDeveloper019NJDeveloper019

Wes,

 

I am doing the same so my testing doesn't take from my 1mb limit.  I am not even able to save the test class as the error comes up immediately as a save error.  How do I view the classes in my browser?  My test class has never been deployed to SalesForce and I can't deploy it because it won't save.  So it does not show up in the Apex Classes section

 

Ralph

wesnoltewesnolte

Create a new test class in the browser like you usually would, and then replace all the code in it with your test class code. Save it and tell me what happens. Also check your other class within the browser, just to make certain the code is being pushed into your Org.

 

Wes

NJDeveloper019NJDeveloper019
That is my problem though.  I cannot create classes in my browser.  I used to be able to but when our trial ended and became a production environment, I could no longer create classes or alter Apex in browser.  So how am I supposed to create a new test class in browser?
Walter@AdicioWalter@Adicio
Is "developer mode" enabled in the user account?
NJDeveloper019NJDeveloper019
The "Development Mode" checkbox is enabled in my user account.
Walter@AdicioWalter@Adicio
I am a newb just ignore me if you already have this. Is "athor apex" on in the user profile?
Walter@AdicioWalter@Adicio

I've noticed I can create visualforce and apex in the browser in every Org except production (production sandbox, free edition, developer edition), if I do not use Google Chrome. Firefox and IE are OK, oh and konqueror and safari do not allow it either for me at least.

 

Anyone get Google Chrome to work? 

NJDeveloper019NJDeveloper019
I built a developer sandbox from production and used the web browser here to build a test class.  I added in the code I have and everything worked.  It saved and my test ran and completed.  Why does this not work in my Eclipse.IDE?
wesnoltewesnolte

So you created a different Org and it worked in the browser? I bet if you link your eclipse to this new org it will work too.. I think it has something to do with your trial ending.

 

Wes