Global classes should not be marked as unused by the inspector

Issue #886 resolved
Aidan Harding created an issue

The code inspector can mark a global class as unused. I think the default should be that global classes may be used outside the current namespace, so they should not be marked unused by the code inspector.

The use-case for me is that I have a managed package trigger handler framework configured by custom metadata. When I write triggers in an org, I write a global class which implements some interfaces from the package (saying that it can handle "before update", "after insert" or whatever). Then I create a custom metadata record to tell the package it needs to run my class on those trigger events. IC won't be able to see that usage because it's hidden in the package (and created by Type.forName()), but it does know the class is global, so it does know something like this usage is possible.

Comments (3)

  1. Scott Wells repo owner

    Well, as an ISV myself I wouldn't want global visibility Apex symbols to be disabled altogether. I was using this just last week as we're refactoring our package contents to determine which global symbols to mark as @Deprecated. In our case, these symbols aren't intended for customer usage but rather for use by our own extension package, so we're more free in these types of refactorings. We also develop both packages in a single project so IC is aware of usages of those symbols (or in this case, lack thereof).

    However, I can definitely see the need for what you're requesting for ISVs who export symbols as global for true external use. I think the right thing to do is to make this a configuration option on the code inspection. That way you can configure it off for your use case and I can configure it on for me.

    This also made me remember that I think for unused global symbols, IC should offer a code intention to mark the symbol as @Deprecated as well as the option to remove it.

  2. Scott Wells repo owner

    The main work for this was delivered in the last release or two. You can now tell the unused declaration inspection to ignore global symbols.

  3. Log in to comment