In VS Code is there a way to see if variables /methods are not referenced? There are some posts like this that reference eclipse, but I couldn't find anything that's recent.

1 Answer 1


There's no tool like that as of yet for Apex. However, there's options available, as outlined in this knowledge article. The complication comes from trying to detect variables that are "unused" within code, but is used in other domains (e.g. Visualforce, Lightning).

For Lightning (Aura and LWC), variables whose names are dimmed are not used. For example:

Example of unused variable

Here, you can see the event parameter is unused, and a darker color than the other variables. This is true for local variables and parameters in methods.

That said, it would be theoretically possible to do so; there's already an API for this (see the KB from above), just that nobody's apparently written this yet. It could be you, if you were so inclined. All extensions can be shared, so if you did so, it'd be a valuable addition to the community.

Alternatively, it may be possible to write a ruleset for Apex PMD to find unused methods and variables and report them as errors. I'm not familiar enough with the syntax yet, but it's definitely not outside the realm of possibility, as far as I can tell.

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