Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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!

share|improve this question
add comment

3 Answers 3

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.

share|improve this answer
    
Thanks Daniel, for the plug, i would love to move this tool on, however i am waiting as you say for the VF references to show up and also avoid the need to recompile everything in the org to get at the SymbolTable external references. I'll keep a close eye on it and am also in contact with the Tooling API developer, so will keep pushing as am I am keen to deliver a tool like this and enable other fancy static analysis tools such as code complexity reports. Though the other thought i also have is Salesforce making the Apex grammer available directly.... ;-) –  Andrew Fawcett Apr 29 at 10:23
    
I've been after an Apex grammar for some time, ref Grammar for creating an Apex parser. I get the appeal of the Tooling API, but surely they must have a defined grammar somewhere internally. I'll continue to to wait patiently on the Tooling API :) –  Daniel Ballinger Apr 29 at 23:51
add comment

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.

share|improve this answer
    
Above answer by Daniel clearly shows that there is tool available and we can use SymbolTable to identify the dependencies. so I do not agree with @Philipp –  AtulRajguru9 Apr 29 at 5:18
    
Also here is one more tool which may help you for code refactoring @Andrew codescan.villagechief.com –  AtulRajguru9 Apr 29 at 5:19
add comment

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
share|improve this answer
    
Didn't work. Hosed my Eclipse and I had to uninstall. I've tried emailing these Village Chief people and even calling them in Australia but no luck getting a response. –  Andrew Jun 9 at 1:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.