Find your content:

Search form

You are here

How can I find unused methods and variables?

 
Share

I would like to search a large project containing many classes, pages, components and triggers for unused methods and variables. How should I do that?

Thanks!


Attribution to: Andrew

Possible Suggestion/Solution #1

There is no tool available that I am aware of. If you suspect that a class is not required anymore (checking it does not have remote actions), you can comment out the class contents. From the Salesforce UI you can then click on the compile all classes link which will throw errors if the compilation failed. Ie another class is referencing code that you have just commented out. It is a lengthy and cumbersome process unfortunately.


Attribution to: Philipp Rackwitz

Possible Suggestion/Solution #2

The Tooling API can be used to retrieve the SymbolTable for each apex class. This Symbol Table will tell you the methods that are defined in the apex class, and the references to methods that are consumed in the externalReferences.

By scanning the methods and corresponding references in each apex classes symbol table you can find methods that aren't called by other apex classes.

Happily, Andrew Fawcett has already made such a tool as a canvas app. See Spring Cleaning Apex Code with the Tooling API.

Note, as this is only scanning the apex classes it won't detect declarative references from Visualforce markup.


Attribution to: Daniel Ballinger

Possible Suggestion/Solution #3

Check out this nice plugin for Eclipse: http://codescan.villagechief.com/eclipse/:

The VillageChief Apex Code Quality tools are the only tool to manage code quality for the Force.com platform. It offers rich visual reporting, lots of metrics, and time-lines to track improvements. The Enterprise version can also be used as a continous integration (CI) tool to continuously run tests on your Force.com Apex unit tests.

Examples of Warnings:

  • Unused fields
  • Long class, field and method names
  • SOQL in loops
  • Duplicate literals
  • Coding standards: naming conventions, fields at top of file, etc
  • Redundant code
  • Code simplification suggestions

Attribution to: Shawn
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33903

My Block Status

My Block Content