We have an global interface inside a global class:

global class SomeClass {

  global interface someInterface() {

    //various methods returning and accepting standard Apex objects only
    String someMethod(String someParameter); 


I know Apex has some limitations regarding the use of inner classes, so, when this package is built, will we run into problems with this approach, or is it permissible?

There's another interface which returns implementations of a further interface:

global interface MyInterface1 {//methods}

global interface myInterface2 {
  MyInterface1 getInstanceOfI1();

These interfaces are to be implemented in another managed package. Implementations of Interface2 will be created using

Type.forName(namespace, classname);

So the implementation of Interface2 should be global, but does the implementation of Interface1 also need to be global?


A global method may not return a public/private class/interface. You will get a compilation error if you attempt to do so. In other words, yes, "myinterface1" must be global if you want to use it in the global interface "myinterface2".

  • The interface it returns is global, but the calling package does not need to know about the implementation, so surely that does not need to be global? – NickJ Oct 1 '18 at 12:55
  • 2
    @NickJ Maybe. If you use Type.forName on a public class outside your namespace, you'll get a null type back, but as long as the other package has a global method that returns a value of the global interface, the class it returns may be public... but only methods in the interface will be accessible, of course, since you won't be able to cast into the public class. – sfdcfox Oct 1 '18 at 13:12
  • Yes, there is a global method which returns a value of the global interface, so should be OK, thanks. – NickJ Oct 1 '18 at 13:56

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.