Amit Chaudhary

Amit Chaudhary

Amit Chaudhary is Salesforce Application & System Architect and working on Salesforce Platform since 2010. He is Salesforce MVP since 2017 and have 17 Salesforce Certificates. He is a active blogger and founder of Apex Hours.

Apex PMD | Static code analysis

PMD is very well known source code analyzer for Java and many more languages. Its also supports Apex. In this session/article we are going to make a static code review for salesforce Apex code using the PMD static code analyzer. Static code analysis is a method for automatically analyzing some source code without executing it.

What is PMD?

PMD stand for Programming Mistake Detector. It is an open source static source code analyzer that reports on issues found within application code. It finds common programming flaws like unused variables, empty catch blocks. It will allow us to have a better quality and avoid maintenance, performance and bug problems in our Apex code.

In this session we will also talk about Apex PMD extension for VsCode. and how to setup Apex PMD.

Setup PMD

  • Download the PMD from here.
  • Extract the zip-archive, e.g. to C:\pmd-bin-6.30.0
  • Add folder C:\pmd-bin-6.30.0\bin to PATH, either
    1. Permanently: Using System Properties dialog > Environment variables > Append to PATH variable
    2. Temporarily, at command line: SET PATH=C:\pmd-bin-6.30.0;%PATH%
  • Execute below command
pmd.bat -d "C:\ApexPMD\MyProject\src\classes" -f html -R "category/apex/design.xml" -reportfile "C:\ApexPMD\output.html"

Customize Apex PMD Rules

You can make your own ruleset file in which you can define a bunch of standard rules and custom rules. Then distribute it to other developers so that they must follow the standards while writing code. Here is sample ruleset.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="" xmlns:xsi="" name="Default ruleset used by the CodeClimate Engine for Apex" xsi:schemaLocation="">
    <description> Custom Rule Set </description>

    <rule ref="category/apex/bestpractices.xml" />
    <rule ref="category/apex/documentation.xml" />
    <!--excluding some rules -->
    <rule ref="category/apex/codestyle.xml">
	<exclude name="WhileLoopsMustUseBraces"/>    


Execute below command to test custom ruleset

pmd.bat -d "C:\ApexPMD\MyProject\src\classes" -f html -R "C:\ApexPMD\ruleset.xml" -reportfile "C:\ApexPMD\output.html"


Learn about Apex PMD Tool. Here is Agenda :

  1. What is PMD
  2. Why do we need tools like PMD (Enforce Clean Code, Security, Agility, Automation)
  3. How to start and how to leverage
  4. Questions & Answers

Here is recording of session.

Speaker           :  Robert Sösemann
Date                 :  Saturday, 27 July 2019 10:00 AM EST ( 7:30 PM IST)

Don’t forget to check Robert Sösemann pluralsight course on “Code Analysis in Apex” freely available to everybody. Please note that we have limit of 100 attendees that can join the online sessions. However, recording will be posted on our YouTube channel. Make sure to subscribe our YouTube channel to get notification for video upload.

Check our “Session in 2019” page for all upcoming and old sessions of 2019.

Sharing is Caring so Share with your friends

Share this article

1 Comment

  • Is APEX PMD, stores the code into any other 3rd party applications? can we use into security projects?

Leave a reply

Keep in Touch

Subscribe for Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 3,229 other subscribers


Our Supporter


Apex Hours

Apex Hours is one stop platform to learn Salesforce skills and technology

Join our Newsletter and get tips and tricks how to explore the salesforce for free!