Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question

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 '14 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 '14 at 23:51

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 '14 at 5:18
Also here is one more tool which may help you for code refactoring @Andrew – AtulRajguru9 Apr 29 '14 at 5:19

Check out this nice plugin for Eclipse:

The VillageChief Apex Code Quality tools are the only tool to manage code quality for the 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 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 '14 at 1:38
I eventually got in touch w/the VillageChief guys and got it working. There are a few versions of their CodeScan tool floating around. One is an Eclipse plugin - don't use it. Another is an AWS EC2 AMI - don't use it. You want the standalone sonarqube plugin. – Andrew Jul 24 '14 at 15:21

Your Answer


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.