I have the following setup:

public with sharing class MyOuterClass extends BaseClass {

  public class MyInnerClass {
    public Id classId {get; private set;}

    public MyInnerClass() {}
    public MyInnerClass(Id classId) {
      this.classId = classId;

Then in an different class entirely I have this method:

public static Map<Id, MyOuterClass.MyInnerclass> getStuff(){
  Map<Id, MyOuterClass.MyInnerclass> results = new Map<Id, MyOuterClass.MyInnerclass>();

  return results;

In the last class there I get InvalidType errors in the Map definitions. It says Invalid type: MyOuterClass.MyInnerclass

Everything I can find says this is the proper use of an inner class. What am I missing?

  • 4
    You've got something else going on here, your code, as is (with the removal of extends BaseClass) compiles just fine. If you remove the base class extension statement, does your code compile? – Mark Pond Aug 8 '17 at 18:10
  • 2
    Yeah this seems like a case of a failed save of MyOuterClass. – Adrian Larson Aug 8 '17 at 18:11
  • 1
    Thanks guys. It was an issue of the two classes each not saving properly because they were dependent on each other. I was able to get them saved properly and now it works. So, no actual issues in the code. – LoneWolfPR Aug 8 '17 at 18:25
  • Might as well add it as an answer so others can benefit from your learning experience. (And please don't forget to accept your answer in a couple days when finally able.) – Adrian Larson Aug 8 '17 at 19:21
  • Happy to let you take the credit. If you add the answer I'll accept it. – LoneWolfPR Aug 9 '17 at 20:17

Almost certainly you get this failure because MyOuterClass failed to save. Depending on your IDE, you may think it compiled when there is really an error. Make sure you get MyOuterClass to compile first, then your second class will be able to reference the MyOuterClass.MyInnerClass type.

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.