I am aware there are couple questions already been asked for this use case and I went through Andrew Fawcett blog post having tool as a canvas app Spring Cleaning Apex Code with the Tooling API

I am looking for solution where I am not be hitting any API but a static analysis by parsing Apex Classes from local directory using python Script or Node.Js.

Has anyone tried this before finding unused methods using python Script or Node.JS

I am new to these scripting languages but will make an effort to see if I can achieve this by statically parsing the local directory, if anyone has tried this before any help will be greatly appreciated.

import os
import csv
import xml.etree.ElementTree as ET 

orgName = 'myDevOrg'
rootdir = 'Local Directory Path'
classfilename2 = orgName + "fileList2.csv"
methodlistFileName2 = orgName + "methodList2.csv"

I am planning to find out methods from Apex classes and will check references of those methods and like that and if no reference is available then it is unused.

  • Do you care about methods called from Aura components? LWC? APIs?
    – sfdcfox
    Mar 16, 2020 at 6:30
  • @sfdcfox Thats in my list but right now I am focusing on finding un-used methods from Apex if I am able to do that will move one step ahead because even SF doesn't show references for classes/methods referenced in Aura components/LWC if we try to delete them , it just checks the SF references. Mar 16, 2020 at 6:33
  • 5
    The Illuminated Cloud IDE does something similar, allowing it to highlight unused methods in real-time in the IDE. It does strike me as a pretty hard problem, so good luck to you
    – Aidan
    Mar 16, 2020 at 9:14

1 Answer 1


I have created a node based CLI script that does a pretty good job of this for APEX references only. I don't look at Aura/Lightning for references, but to be fair, you should have unit tests for any Apex Enabled methods anyway so it shouldn't be necessary. In any case, the script iterates over your local project files to first find all custom method declarations then finds all references to those declarations. This is in no way commercial grade but I've used it on a pretty big org to find dead code. It generates a MD file with all the classes and method signatures and a CSV file listing all the declarations, reference count, and which file(s) the references are in. Note it collapses overloads currently, so if there are multiple method signatures sharing the same name, it gives the total count for all versions of that method, not each signature independently.

Feel free to log bugs to the Github. Enjoy!


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .