Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hello and thank you for taking the time to read my question. I am getting near the end of finally testing my new trigger, and started to clean up my code. I decided(as recommended by others in this community) to create a separate class that contains methods to fill Accounts, Opportunities and other objects. However, when I call the class and it's method I get the error: Type is not visible

This is my class with the methods described above.

public class TestUtil 
    public static Contact initContact(){
        *   Create a Contact
        *   Insert Contact into DB
        *   Return Contact back into testPage in order to use information
        Contact testContact = new Contact (
                    firstName = 'Firstly', lastName = 'Lastly', email = ''
        insert testContact;
        return testContact;

My test class calling this:

private class Test_Trig_Opportunity_CreateServContract {                
    static testMethod void testTriggerOpp() {
        //  Initiliazed Class that contains methods to create SF Objects(Account, Opportunity, etc. )
      TestUtil initObj = new TestUtil();    
        //initialize test variables (called from test variable class)        
      Contact testContact = initObj.initContact();                                                                  

I also tried without calling the class at first:

private class Test_Trig_Opportunity_CreateServContract {                
    static testMethod void testTriggerOpp() {               
        //initialize test variables (called from test variable class)        
     Contact testContact = TestUtil.initContact();  

Both bring the same error. Thank you again for your time.

share|improve this question
Second one (with just a call to static method) should work fine 1st one is an overkill ;) Does it say which Type is not visible? Does initContact() look exactly like this? Isn't marked private or with some System.runAs? Did TestUtil save succesfully to server? – eyescream Feb 19 '13 at 21:57
Your test passed in my DE org. I had to add the closing curly braces, but otherwise the second option worked perfectly. – Brad Ullery Feb 19 '13 at 22:15
Thanks Brad and eyescream for your responses. It helped me figure out that it was user error and I needed to compile the testclass – jnoel10 Feb 19 '13 at 22:24
up vote 4 down vote accepted

Hi you're second attempt is correct. Since your initContact() method is static you don't need to initialize an instance of TestUtil to access it, i.e. TestUtil.initContact()

If you're still getting the method visibility issue you should log a case with support. I've been using that exact same technique for the past 5 years and haven't had any issues, so it sounds like you may have hit a bug.

share|improve this answer
Thanks Ralph, the error was user error. I needed to run the TestUtil class first and then run the other class after. I figured since it 'Run Tests' it would have run everything. – jnoel10 Feb 19 '13 at 22:22
Nice work figuring it out, best of luck with the project – Ralph Callaway Feb 19 '13 at 22:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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