ruleDescriptionurlkpiexample
ApexUnitTestClassShouldHaveAssertsApex unit tests should System.assert() or assertEquals() or assertNotEquals()https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#apexunittestclassshouldhaveassertsMaintainability
ApexUnitTestMethodShouldHaveIsTestAnnotationApex test methods should have @isTest annotation.https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotationMaintainability
ApexUnitTestShouldNotUseSeeAllDataTrueApex unit tests should not use @isTest(seeAllData = true)https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#apexunittestshouldnotuseseealldatatrueMaintainability
AvoidGlobalModifierAvoid using global modifierhttps://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#avoidglobalmodifierMaintainability
AvoidLogicInTriggerAvoid logic in triggershttps://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#avoidlogicintriggerMaintainability
DebugsShouldUseLoggingLevelCalls to System.debug should specify a logging level.https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevelMaintainability
UnusedLocalVariableVariable ''{0}'' defined but not usedhttps://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#unusedlocalvariableMaintainability
AvoidDeeplyNestedIfStmtsAvoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain.https://pmd.github.io/latest/pmd_rules_apex_design.html#avoiddeeplynestedifstmtsMaintainability_x000D_
public class Foo {_x000D_
public void bar(Integer x, Integer y, Integer z) {_x000D_
if (x>y) {_x000D_
if (y>z) {_x000D_
if (z==x) {_x000D_
// !! too deep_x000D_
}_x000D_
}_x000D_
}_x000D_
}_x000D_
}_x000D_
AvoidDirectAccessTriggerMapAvoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Triggers should be bulkified and iterate through the map to handle the actions for each item separately.https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#avoiddirectaccesstriggermapMaintainability
AvoidNonExistentAnnotationsApex supported non existent annotations for legacy reasons._x000D_
In the future, use of such non-existent annotations could result in broken apex code that will not compile._x000D_
This will prevent users of garbage annotations from being able to use legitimate annotations added to Apex in the future._x000D_
A full list of supported annotations can be found at https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation.htm
https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#avoidnonexistentannotationsMaintainability
EmptyCatchBlockEmpty Catch Block finds instances where an exception is caught, but nothing is done._x000D_
In most circumstances, this swallows an exception which should either be acted on_x000D_
or reported.
https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#emptycatchblockMaintainability
EmptyIfStmtEmpty If Statement finds instances where a condition is checked but nothing is done about it.https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#emptyifstmtMaintainability
EmptyStatementBlockEmpty block statements serve no purpose and should be removed.https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#emptystatementblockMaintainability
EmptyWhileStmtEmpty While Statement finds all instances where a while statement does nothing._x000D_
If it is a timing loop, then you should use Thread.sleep() for it; if it is_x000D_
a while loop that does a lot in the exit expression, rewrite it to make it clearer.
https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#emptywhilestmtMaintainability
MethodWithSameNameAsEnclosingClassNon-constructor methods should not have the same name as the enclosing class.https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#methodwithsamenameasenclosingclassMaintainability
TestMethodsMustBeInTestClassesTest methods marked as a testMethod or annotated with @IsTest,_x000D_
but not residing in a test class should be moved to a proper_x000D_
class or have the @IsTest annotation added to the class._x000D_
_x000D_
Support for tests inside functional classes was removed in Spring-13 (API Version 27.0),_x000D_
making classes that violate this rule fail compile-time. This rule is mostly usable when_x000D_
dealing with legacy code.
https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#testmethodsmustbeintestclassesMaintainability