You need to sign in to do that
Don't have an account?

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
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
Can you use something like this?
public boolean criteriaVal { get; set;} {criteriaVal=false;}
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
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);
}
}
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
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
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
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
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
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?
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