RemoveUnusedMethod Rule (Pilot)

RemoveUnusedMethod is a path-based analysis rule that detects many methods contained in your code that aren’t invoked from any entry points that Graph Engine recognizes. It detects static methods and instance methods.

RemoveUnusedMethod recognizes these entry points.

  • @AuraEnabled-annotated methods.
  • @InvocableMethod-annotated methods.
  • @NamespaceAccessible-annotated methods.
  • @RemoteAction-annotated methods.
  • Any method returning a `PageReference`` object.
  • Public-scoped methods on Visualforce Controllers.
  • Global-scoped methods on any class.
  • Messaging.InboundEmailResult handleInboundEmail() methods on implementations of Messaging.InboundEmailHandler.
  • Any method targeted during invocation.

RemoveUnusedMethod uses sources like ApexFlsViolationRule does, but the RemoveUnusedMethod sinks are different. Instead of seeking DML operations that occur in the course of a path, RemoveUnusedMethod sinks track all method invocations that occur on that path and use that information to identify methods that are never invoked.

Match any violation message that you receive with this case to understand more about the violation.

Method %s in class %s isn’t used in any path from any recognized entry point.

Because no invocations of the indicated method were found in the paths originating from the identified entry points, the method is unnecessary and can be deleted.

  • RemoveUnusedMethod works on static methods and instance methods. Constructors aren't detected.
  • Global methods are intentionally excluded because their external usage is assumed.
  • If the set of files included in --target is smaller than the files included in --projectdir, then RemoveUnusedMethod can return unexpected results. For that reason, we recommend running this rule against your whole codebase, not against individual files.