ApexUnitTestClassShouldHaveAssertsApex unit tests should System.assert() or assertEquals() or assertNotEquals()
ApexUnitTestMethodShouldHaveIsTestAnnotationApex test methods should have @isTest annotation.
ApexUnitTestShouldNotUseSeeAllDataTrueApex unit tests should not use @isTest(seeAllData = true)
AvoidGlobalModifierAvoid using global modifier
AvoidLogicInTriggerAvoid logic in triggers
DebugsShouldUseLoggingLevelCalls to System.debug should specify a logging level.
UnusedLocalVariableVariable ''{0}'' defined but not used
AvoidDeeplyNestedIfStmtsAvoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain.
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_
AvoidDirectAccessTriggerMapAvoid directly accessing Trigger.old and as it can lead to a bug. Triggers should be bulkified and iterate through the map to handle the actions for each item separately.
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
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.
EmptyIfStmtEmpty If Statement finds instances where a condition is checked but nothing is done about it.
EmptyStatementBlockEmpty block statements serve no purpose and should be removed.
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.
MethodWithSameNameAsEnclosingClassNon-constructor methods should not have the same name as the enclosing class.
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_
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.