There are a series of best practices that Salesforce recommends you to follow when working on the technology. Whether you are an admin or consultant doing the configuration or a developer writing code, these best practices help you build a solid foundation, improve quality, avoid making mistakes and become better in what you do.
But this is also true that most of the time these best practices are not being followed. This may be because people are ignorant, following requires extra effort and/or extra investment in tool/technology.
If you are a Salesforce developer, here is one such tool which is free and easy to use and will guide you to bake quality in your code as you are developing it. After learning how to do it, there will be no reason for you not to use it in your day to day work and become an awesome developer. 🙂
Called Apex PMD (stands for Programming Mistake Detector), this is a tool that analyses source code to flag deviation from best practices, programming errors, bugs, stylistic errors, and suspicious constructs. You can perform Apex Static Analysis directly in Visual Studio Code on Apex and Visualforce files. Apex PMD is available as an extension for Visual Studio Code.
(If you haven’t yet switched to Visual Studio Code for your Salesforce development work, you may want to refer to my step-by-step guide on “How To Get Started with Visual Studio Code for Salesforce“)
With Apex PMD, analysis can be performed when file is opened or closed. It can be performed on a single file or on the entire workspace at once. You can also define your custom rulesets in .jar files to meet your code compliance needs.
Apex PMD is a very useful tool. You can refer to the suggestions/problems highlighted by the tool from the initial stages in development cycle and make changes in your code accordingly. This will help you learn and follow the best practices right from the beginning, making you a better developer in the process with high quality work.
Follow this guide and in less than 15 minutes (literally), you will learn how to install and use Apex PMD. Here’s what this guide covers:
- Install Apex PMD in Visual Studio Code
- Perform Apex Static Analysis on File
- Perform Apex Static Analysis on Workspace
- Clear analysis Problems from Visual Studio Code Panel
- Set Preferences for Apex PMD
After going through it, you will come to know that you can have a code companion to guide you in developing compliant, efficient, secure, scalable and sustainable applications.
If you haven’t yet started using Visual Studio Code for Salesforce development, I will highly recommend to start using the same as Salesforce itself has come up with an extension on VS Code and will continue to enhance it.
References & Useful URLs
- Apex PMD Listing – https://marketplace.visualstudio.com/items?itemName=chuckjonas.apex-pmd
- YouTube Video (73:08 minutes) – codeLive: Improve Apex Code Quality with PMD
- Blog post – How To Get Started with Visual Studio Code for Salesforce