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

Basic Question: Assigning Value to Class Variable
Hi,
I have a very basic APEX question. How do I assign values to class variables? Take the example below. The last two lines give a compile time error of "unexpected token: '=' ". The code below is just a simple snippet that I've created to demonstrate the problem that I'm having. The actual code that I am working with is a generated class from importing a WSDL. In my code, I'm trying to create an instance of the message class so that I can pass it to the service invocation method. But, as you can see, I'm getting stuck just trying to assign values to the class.
outerClass out = new outerClass(); //not sure if this is necessary since I have not created a constructor
out.IC = new innerClass();
out.IC.str = 'A string'; //it seems like this statement should be sufficient without the one above it.
}
The syntax is fine, its just your last 3 lines of code are in no man's land. It ought to be inside a constructor or method.
e.g this compile fine: