Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.
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!!!!!!!!

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
@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. –  Jesse Altman Feb 13 '13 at 14:39
add comment

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);
    }
}
share|improve this answer
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. –  Jesse Altman Feb 13 '13 at 14:36
2  
@JesseAltman just updated my example –  mast0r 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! –  Jesse Altman Feb 13 '13 at 15:17
add comment

Your Answer

 
discard

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.