I don't have a Java background and am working on a class where I'd like to be able to call inner classes from withing methods of the outer class. As much of Apex is implicit and I'm still learning, I sometimes find the proper syntax for things like this a bit confusing.

As I understand it, all methods in a class are executed sequentially and there's no simple way to call one from another. Am I correct on that? If so, the solution seems to have an outer class that could call inner classes ass needed causing only the necessary code to execute.

Exactly how would I set up the call outs for that kind of class? Here's some pseudo-code for what I'm trying to accomplish and how I think the classes and methods should be arranged:

public class myNestedClssUtil {
    public class myNestedClssUtilEntry {
        public string MyStrng;
        public processMyStrng() {
            // code to process MyStrng
            // Decision Tree
            if (MyString, Condition A) {
                call to MyNestedClss1(MyStrng);
                Return MyStrng;
            } else {
                call to MyNestedClss2(MyStrng);
                Return MyString;
        private class MyNestedClss1 {
            private class MyNestedClss1Entry {
                private string inStrng1;
                private procInStrng1() {
                    //code to process inStrng1
                    Return inStrng1;
        private class MyNestedClss2 {
            private class MyNestedClss2Entry {
                private string inStrng2;
                private procInStrng2() {
                     //code to process inStrng2
                     Return inStrng2;

I should add that this is for a class where a string is passed into the class, processed and then returned. I've not shown a constructor anywhere above. This is intended as a utility class for use inside of a trigger. Thank you for your assistance and input on how to do this using the correct syntax.

1 Answer 1


It will be great if you can indent your code for better readability.

And of course you can nest classes within each other.

You would need to instantiate the child class and use the object to access its methods.

Some sample code:

public OuterClass
    //Declarations and methods.

    //Here is how you would access the child class.

    InnerClass obj1 = new InnerClass();

    //Invoke method

    public InnerClass
        public String Name {get; set;}

         public InnerClass()

        public String doSomething()


Some links to help you.



  • Thank you Richard for the assistance. Its much appreciated. I understand your comments about indenting. I was having difficulty with the site's editor and couldn't seem to paste everything as a block of code, making it slow to just get my post entered. I'm headed straight to the links you've provided. :)
    – crmprogdev
    Feb 7, 2013 at 21:13
  • No problem :) I know posting code takes some getting used to.
    – Richard N
    Feb 7, 2013 at 21:14
  • @crmprogdev For future reference, the code editing here is just done with spaces when using large blocks of code like that. I edited the post for you to make the code more readable. Enjoy the site! Feb 7, 2013 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .