PMD is a well known Static code analyzer for Java and many other languages. It also supports Salesforce Apex as well.

Source code analysis is important during development cycle to point out weaknesses in code and to improve overall quality. Examples are:

  • Code Complexity Measures (e.g. Lines of Code, Nesting Level, Code Clones)
  • Dynamic Related Measures (e.g. Code Coverage, Bugs per Line of Code, Feature Usage)

For Salesforce Apex, the freeware PMD is a recommended tool to carry out Static Code Analysis. It provides an easy to use Plug-in for Eclipse and comes with a prebuilt rule set which is deployable right after installation:

  • ApexUnit:        These rules deal with different problems that can occur with Apex unit tests. (Rules: ApexUnitTestClassShouldHaveAssertsApexUnitTestShouldNotUseSeeAllDataTrue)
  • Braces:            The Braces ruleset contains rules regarding the use and placement of braces. (Rules: IfStmtsMustUseBracesWhileLoopsMustUseBracesIfElseStmtsMustUseBracesForLoopsMustUseBraces)
  • Complexity:    The Complexity ruleset contains rules that find problems related to code size or complexity. (Rules: AvoidDeeplyNestedIfStmts, ExcessiveParameterList, ExcessiveClassLength, NcssMethodCount, NcssTypeCount, NcssConstructorCount, StdCyclomaticComplexity, TooManyFields, ExcessivePublicCount)
  • Performance: The Performance ruleset contains a collection of good practices which should be followed. (Rules: AvoidSoqlInLoopsAvoidDmlStatementsInLoops)

General information on PMD and the rules available for APEX:


There are multiple ways to use PMD in Salesforce Apex code, however this blog will focus on #1 to set-up standalone static code analysis in Eclipse

  • We can run static code analysis standalone
  • It can be part of ANT build to generate error reports
  • Jenkins can use it to generate nice report around code quality
  • Eclipse can use it as a plug-in to generate report

Steps to be followed during Installation and set-up PMD in Eclipse:

  1. In Eclipse, click on Help -> Install New Software.
  2. Click on Add.
  3. Enter the following:

and click OK.

  1. You should see PMD for Eclipse 4. Select the checkbox next to it and click Next >.
  2. You’ll need to accept the license and confirm you want to install a plugin that is not digitally signed. Go ahead and install it anyway.
  3. Restart eclipse. 

Run PMD:


Right click on project -> Property -> Select PMD


It’ll show you the code violation.


Read More

Two of the closing sessions at this year’s Salesforce Dreamforce, were amongst the most powerful I have ever seen.

The theme was ‘Personal Empowerment: How to Live a Successful Life’


The first session was with Deepak Chopra. It’s the first time I have seen Deepak Chopra and his discussion on the 3 remaining mysteries of the universe, the equation for human happiness, the positive aspects of human health and wellbeing, and how these points impact our daily lives was amazing.  Deepak, at 72 looks half his age and is an incredible speaker.


This session was followed by the founder of Huffington Post, Arianna Huffington, another fantastic speaker that relayed how her new business venture “Thrive” came about.  She relayed the experience of having a massive heart attack at work and how this changed her view of the role that stress plays in people’s lives – including a commitment to stop utilising technology.


‘How to Live a Successful Life with Arianna Huffington’


The discussion around both these speakers included how Salesforce are driving better working habits throughout their organisation in an effort to minimise stress.  There were many anecdotes discussed but the one that struck me most was a statement from Amazon founder Jeff Bezos, who measured his own performance both before and after adopting some techniques to minimise mobile phone use, achieving 8 hours of sleep, Yoga and Meditation.  His statement that “the shareholders of Amazon receive a measurably better performance” was inspiring.


Both sessions are on Dreamforce Live and I recommend that you watch them – they are inspiring, informative and humorous!


‘Personal Empowerment: How to Live a Successful Life: Deepak Chopra’


‘Personal Empowerment: How to Live a Successful Life: Arianna Huffington’


Read More