Skip to main content
Hi,

If I decalre a variable in the first part of my class outside any of the methods, it should be available within all of my methods yes?  But for some reason that's not working here, I don't understand what's wrong.  There must be somethign I'm missing

Thanks,

public class ContactReclassTest {

String confirstName;

String conlastName;

List<Contact> conList = New List<Contact>(); // this should be seen by within all methods yes?

ContactReclassTest() {

conFirstName = 'Mathew';

conlastName = 'Andresen';

}

public static void createContacts() {

List<Contact> conList = New List<Contact>(); // If I don't put this in it says the variable doesn't exist

for(Integer i = 0; i < 5; i++) {

Contact con = new Contact(FirstName = 'Mathew', LastName = ('Andresen'+ i) ); //can't find the other strings I declared either

conList.add(con);

}

insert(conList);

}

}

 
2 answers
  1. Feb 20, 2015, 6:27 PM
    You are trying to reference the member variable from a static method. This can not be done. You have to make variable static as well to access it.
0/9000