3
public with sharing class classA{
           public  map<string,map<string,innerclass>> methodA(){
             map<string,map<string,innerclass>> fieldA = new map<string,map<string,innerclass>>();
             //some code here
             map<string,innerclass> fieldB = new map<string,innerclass>();
             fieldB.put('str',innerclassval);
             fieldA.put('str1',fieldB);
             return fieldA;
           }

In fieldA value will be something like this ------- str1={str={link1,link2}}

My Second Class is

public class ClassB{
   public ClassB(){
    classA ca = new classA();
    map<string,map<string,innerclass>> inmap = ca.methodA(); // getting error as Invalid type innerclass

   }
}

Now how can I call this class in another class where I need link1,link2 Values .Help!!!!!!!!

4

First class:

public class ClassA{
    public ClassA(){
    }

    public Map<String,Map<String,InnerClass>> methodA(){
        Map<string,map<String,InnerClass>> fieldA = new Map<String,Map<String,InnerClass>>();
        //some code here
        Map<String,InnerClass> fieldB = new Map<String,InnerClass>();
        fieldB.put('str',innerclassval);
        fieldA.put('str1',fieldB);
        return fieldA;
    }

    public class InnerClass{
        public InnerClass(){

        }
    }
}

Reference class:

public class ClassB{
    public ClassB(){
    }
    public void fakeMethod(){
        ClassA classAInstance = new ClassA();
        Map<String, Map<String, ClassA.InnerClass>> fullMapInstance = classAInstance.methodA();
    }
}

You should check out the Apex documentation on defining classes. Here is a good example on Extending Apex Classes. In fact, I would recommend just reading up on all the documentation Salesforce provides on Classes, Objects, and Interfaces.

1
  • @EagerinSf I don't know what you are trying to do now to be honest. Can you update your original question with the code you are getting this error on please? I would like to help you, but I am not understanding your problem now I think. Feb 13 '13 at 14:39
3

Can't you just create a new reference of cassA in classB and then call that method like this:

public with sharing class classA{
    public  map<string,map<string,innerclass>> methodA(String param1){
        map<string,map<string,innerclass>> fieldA = new map<string,map<string,innerclass>>();
        //some code here
        map<string,innerclass> fieldB = new map<string,innerclass>();
        fieldB.put('str',innerclassval);

        if(param1 == null)
            String s = ... // generating the String because the param1 is unll
            param1 = s;
        }

        fieldA.put(param1,fieldB);
        return fieldA;
    }
}

public with sharing class classB{
    public classB(){
        String s = {link1,link2};
        classA c1 = new classA();
        map<string,map<string,innerclass>> m = c1.methodA(s);
    }
}
3
  • 1
    Can you add your second class to your original post and show how you are referencing this map? I am a bit confused as to what you are trying to do now. Feb 13 '13 at 14:36
  • 2
    @JesseAltman just updated my example Feb 13 '13 at 15:15
  • 1
    My original comment was towards a comment @EagerinSf put on your question but he apparently deleted it. I understood what you were referencing. Thanks for taking the time to help him out though! Upvoted! Feb 13 '13 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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