GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PMD Source Code Analyzer Project
  • Nav
  • Download
  • GitHub

This view

  • Original page
  • New address

GeezerVison is showing docs.pmd-code.org — Apex Rules | PMD Source Code Analyzer

 
  • PMD 7.31.0-SNAPSHOT
  • Release date: 28-December-2026
  • About
    • Home
    • Release notes
    • Getting help
    • Release policies
    • Support lifecycle
    • Security
  • User Documentation
    • Migration Guide for PMD 7
    • Installation and basic CLI usage
    • Making rulesets
    • Configuring rules
    • Best practices
    • Suppressing warnings
    • Incremental analysis
    • PMD CLI reference
    • PMD Report formats
    • 3rd party rulesets
    • Signed Releases
    • CPD reference
      • Copy-paste detection
      • CPD Report formats
    • Extending PMD
      • Introduction to writing rules
      • Your first rule
      • XPath rules
      • Java rules
      • Rule designer reference
      • Defining rule properties
      • Rule guidelines
      • Testing your rules
      • Creating (XML) dump of the AST
    • Tools / Integrations
      • Maven PMD Plugin
      • Gradle
      • Ant
      • PMD Java API
      • bld PMD Extension
      • CI integrations
      • IDE Plugins
      • Other Tools / Integrations
  • Rule Reference
    • Apex Rules
      • Index
      • Best Practices
      • Code Style
      • Design
      • Documentation
      • Error Prone
      • Performance
      • Security
    • HTML Rules
      • Index
      • Best Practices
    • Java Rules
      • Index
      • Best Practices
      • Code Style
      • Design
      • Documentation
      • Error Prone
      • Multithreading
      • Performance
      • Security
    • Java Server Pages Rules
      • Index
      • Best Practices
      • Code Style
      • Design
      • Error Prone
      • Security
    • JavaScript Rules
      • Index
      • Best Practices
      • Code Style
      • Error Prone
      • Performance
    • Kotlin Rules
      • Index
      • Best Practices
      • Error Prone
    • Maven POM Rules
      • Index
      • Error Prone
    • Modelica Rules
      • Index
      • Best Practices
    • PLSQL Rules
      • Index
      • Best Practices
      • Code Style
      • Design
      • Error Prone
    • Salesforce Visualforce Rules
      • Index
      • Security
    • Scala Rules
      • Index
    • Swift Rules
      • Index
      • Best Practices
      • Error Prone
    • Velocity Template Language (VTL) Rules
      • Index
      • Best Practices
      • Design
      • Error Prone
    • WSDL Rules
      • Index
    • XML Rules
      • Index
      • Best Practices
      • Error Prone
    • XSL Rules
      • Index
      • Code Style
      • Performance
  • Language-Specific Documentation
    • Overview
    • Language configuration
    • Apex
    • C/C++
    • C#
    • CSS
    • Coco
    • Dart
    • Fortran
    • Gherkin
    • Go
    • HTML
    • Java
    • JavaScript / TypeScript
    • JSP
    • Julia
    • Kotlin
    • Lua
    • Matlab
    • Modelica
    • Objective-C
    • Perl
    • PHP
    • PLSQL
    • Python
    • Ruby
    • Rust
    • Scala
    • Swift
    • T-SQL
    • Visualforce
    • Velocity Template Language (VTL)
    • XML and XML dialects
  • Developer Documentation
    • Contributing
      • Contributing
      • Developer resources
      • Newcomers' Guide
      • Writing documentation
    • Building PMD
      • General Info
      • Building PMD from source
      • Building PMD with IntelliJ IDEA
      • Building PMD with Eclipse IDE
      • Building PMD with VS Code IDE
      • Building PMD with Netbeans IDE
    • Roadmap
    • GitHub Actions Workflows
    • How PMD works
    • Logging
    • Pmdtester
    • Rule Deprecation Policy
    • Major contributions
      • Rule Guidelines
      • Adding a new dialect
      • Adding a new language (JavaCC)
      • Adding a new language (ANTLR)
      • Adding a new CPD language
    • Experimental features
      • List of experimental Features
  • Project documentation
    • Trivia about PMD
      • PMD in the press
      • Products & books related to PMD
      • Similar projects
      • What does 'PMD' mean?
    • Logo
    • FAQ
    • License
    • Credits
    • Old Release Notes
      • Release Notes PMD 7.x
      • Detailed Release Notes PMD 7.0.0
      • Release Notes PMD 6.x
      • Release Notes PMD 5.x
      • Release Notes PMD 4.x and earlier
    • Decisions
    • Project management
      • Infrastructure
      • Release process
      • Merging pull requests
      • Main Landing page

Apex Rules

Index of all built-in rules available for Apex
Table of Contents

Best Practices

Rules which enforce generally accepted best practices.
  • ApexAssertionsShouldIncludeMessage: The second parameter of System.assert/third parameter of System.assertEquals/System.assertNotEqua…
  • ApexUnitTestClassShouldHaveAsserts: Apex unit tests should include at least one assertion. This makes the tests more robust, and usi…
  • ApexUnitTestClassShouldHaveRunAs: Apex unit tests should include at least one runAs method. This makes the tests more robust, and …
  • ApexUnitTestClassShouldHaveRunRelevantTestsAnnotation: Apex unit test classes should declare either ‘@IsTest(critical=true)’ or ‘@IsTest(testFor=’…’)’…
  • ApexUnitTestMethodShouldHaveIsTestAnnotation: Apex test methods should have ‘@isTest’ annotation instead of the ‘testMethod’ keyword, as ‘testM…
  • ApexUnitTestShouldNotUseSeeAllDataTrue: Apex unit tests should not use @isTest(seeAllData=true) because it opens up the existing database…
  • AvoidFutureAnnotation: Usage of the ‘@Future’ annotation should be limited. The ‘@Future’ annotation is a legacy way to …
  • AvoidGlobalModifier: Global classes should be avoided (especially in managed packages) as they can never be deleted or…
  • AvoidLogicInTrigger: As triggers do not allow methods like regular classes they are less flexible and suited to apply …
  • DebugsShouldUseLoggingLevel: The first parameter of System.debug, when using the signature with two parameters, is a LoggingLe…
  • QueueableWithoutFinalizer: Detects when the Queueable interface is used but a Finalizer is not attached. It is b…
  • UnusedLocalVariable: Detects when a local variable is declared and/or assigned but not used.

Code Style

Rules which enforce a specific coding style.
  • AnnotationsNamingConventions: Apex, while case-insensitive, benefits from a consistent code style to improve readability and ma…
  • ClassNamingConventions: Configurable naming conventions for type declarations. This rule reports type declara…
  • FieldDeclarationsShouldBeAtStart: Field declarations should appear before method declarations within a class. Note: Since PMD 7.21….
  • FieldNamingConventions: Configurable naming conventions for field declarations. This rule reports variable declarations …
  • ForLoopsMustUseBraces: Avoid using ‘for’ statements without using surrounding braces. If the code formatting or indentat…
  • FormalParameterNamingConventions: Configurable naming conventions for formal parameters of methods. This rule reports f…
  • IfElseStmtsMustUseBraces: Avoid using if..else statements without using surrounding braces. If the code formatting …
  • IfStmtsMustUseBraces: Avoid using if statements without using braces to surround the code block. If the code …
  • LocalVariableNamingConventions: Configurable naming conventions for local variable declarations. This rule reports va…
  • MethodNamingConventions: Configurable naming conventions for method declarations. This rule reports method dec…
  • OneDeclarationPerLine: Apex allows the use of several variables declaration of the same type on one line. However, it ca…
  • PropertyNamingConventions: Configurable naming conventions for property declarations. This rule reports property…
  • WhileLoopsMustUseBraces: Avoid using ‘while’ statements without using braces to surround the code block. If the code forma…

Design

Rules that help you discover design issues.
  • AvoidBooleanMethodParameters: Boolean parameters in a system’s API can make method calls difficult to understand and …
  • AvoidDeeplyNestedIfStmts: Avoid creating deeply nested if-then statements since they are harder to read and error-prone to …
  • CognitiveComplexity: Methods that are highly complex are difficult to read and more costly to maintain. If you include…
  • CyclomaticComplexity: The complexity of methods directly affects maintenance costs and readability. Concentrating too m…
  • ExcessiveClassLength: Deprecated Excessive class file lengths are usually indications that the class may be burdened with excessiv…
  • ExcessiveParameterList: Methods with numerous parameters are a challenge to maintain, especially if most of them share th…
  • ExcessivePublicCount: Classes with large numbers of public methods, attributes, and properties require disproportionate…
  • NcssConstructorCount: Deprecated This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of l…
  • NcssCount: This rule uses the NCSS (Non-Commenting Source Statements) metric to determine the number of line…
  • NcssMethodCount: Deprecated This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of l…
  • NcssTypeCount: Deprecated This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of l…
  • StdCyclomaticComplexity: Complexity directly affects maintenance costs is determined by the number of decision points in a…
  • TooManyFields: Classes that have too many fields can become unwieldy and could be redesigned to have fewer field…
  • UnusedMethod: Avoid having unused methods since they make understanding and maintaining code harder. This rule …

Documentation

Rules that are related to code documentation.
  • ApexDoc: This rule validates that: ApexDoc comments are present for classes, methods, and properties th…

Error Prone

Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
  • ApexCSRF: Having DML operations in Apex class constructor or initializers can have unexpected side effects:…
  • AvoidDirectAccessTriggerMap: Avoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Triggers should be …
  • AvoidHardcodingId: When deploying Apex code between sandbox and production environments, or installing Force.com App…
  • AvoidInterfaceAsMapKey: In Apex, when a ‘Map’ uses an interface as key and an abstract class implements that interface an…
  • AvoidNonExistentAnnotations: Apex supported non existent annotations for legacy reasons. In the future, use of such non-…
  • AvoidStatefulDatabaseResult: Using instance variables of the following types (or collections of these types) within a stateful…
  • EmptyCatchBlock: Empty Catch Block finds instances where an exception is caught, but nothing is done. In mos…
  • EmptyIfStmt: Empty If Statement finds instances where a condition is checked but nothing is done about it.
  • EmptyStatementBlock: Empty block statements serve no purpose and should be removed.
  • EmptyTryOrFinallyBlock: Avoid empty try or finally blocks - what’s the point?
  • EmptyWhileStmt: Empty While Statement finds all instances where a while statement does nothing. If it is a …
  • InaccessibleAuraEnabledGetter: In the Summer ‘21 release, a mandatory security update enforces access modifiers on Apex properti…
  • InvocableClassNoArgConstructor: Apex classes containing @InvocableVariable properties used for flow parameters must expose a visi…
  • MethodWithSameNameAsEnclosingClass: Non-constructor methods should not have the same name as the enclosing class.
  • OverrideBothEqualsAndHashcode: Override both ‘public Boolean equals(Object obj)’, and ‘public Integer hashCode()’, or override n…
  • TestMethodsMustBeInTestClasses: Test methods marked as a testMethod or annotated with @IsTest, but not residing in a test c…
  • TypeShadowsBuiltInNamespace: This rule finds Apex classes, enums, and interfaces that have the same name as a class, enum, or …

Performance

Rules that flag suboptimal code.
  • AvoidDebugStatements: Debug statements contribute to longer transactions and consume Apex CPU time even when debug logs…
  • AvoidNonRestrictiveQueries: When working with very large amounts of data, unfiltered SOQL or SOSL queries can quickly cause …
  • EagerlyLoadedDescribeSObjectResult: This rule finds ‘DescribeSObjectResult’s which could have been loaded eagerly via ‘SObjectType.ge…
  • OperationWithHighCostInLoop: This rule finds method calls inside loops that are known to be likely a performance issue. These …
  • OperationWithLimitsInLoop: Database class methods, DML operations, SOQL queries, SOSL queries, Approval class methods, Email…

Security

Rules that flag potential security flaws.
  • ApexBadCrypto: The rule makes sure you are using randomly generated IVs and keys for ‘Crypto’ calls. Hard-wiring…
  • ApexCRUDViolation: The rule validates you are checking for access permissions before a SOQL/SOSL/DML operation. Sinc…
  • ApexDangerousMethods: Checks against calling dangerous methods. For the time being, it reports: Against ‘FinancialForc…
  • ApexInsecureEndpoint: Checks against accessing endpoints under plain http. You should always use https for security.
  • ApexOpenRedirect: Checks against redirects to user-controlled locations. This prevents attackers from redirecting u…
  • ApexSharingViolations: Detect classes declared without explicit sharing mode if DML methods are used. This forces the de…
  • ApexSOQLInjection: Detects the usage of untrusted / unescaped variables in DML queries.
  • ApexSuggestUsingNamedCred: Detects hardcoded credentials used in requests to an endpoint. You should refrain from hardcoding…
  • ApexXSSFromEscapeFalse: Reports on calls to ‘addError’ with disabled escaping. The message passed to ‘addError’ will be d…
  • ApexXSSFromURLParam: Makes sure that all values obtained from URL parameters are properly escaped / sanitized to avoid…

Additional rulesets

  • quickstart (rulesets/apex/quickstart.xml):

    Quickstart configuration of PMD for Salesforce.com Apex. Includes the rules that are most likely to apply everywhere.

    It contains the following rules:

    AnnotationsNamingConventions, ApexBadCrypto, ApexCRUDViolation, ApexCSRF, ApexDangerousMethods, ApexDoc, ApexInsecureEndpoint, ApexOpenRedirect, ApexSharingViolations, ApexSOQLInjection, ApexSuggestUsingNamedCred, ApexUnitTestClassShouldHaveAsserts, ApexUnitTestClassShouldHaveRunAs, ApexUnitTestShouldNotUseSeeAllDataTrue, ApexXSSFromEscapeFalse, ApexXSSFromURLParam, AvoidDeeplyNestedIfStmts, AvoidDirectAccessTriggerMap, AvoidGlobalModifier, AvoidHardcodingId, AvoidLogicInTrigger, AvoidNonExistentAnnotations, ClassNamingConventions, CyclomaticComplexity, DebugsShouldUseLoggingLevel, EmptyCatchBlock, EmptyIfStmt, EmptyStatementBlock, EmptyTryOrFinallyBlock, EmptyWhileStmt, ExcessiveParameterList, ExcessivePublicCount, FieldNamingConventions, ForLoopsMustUseBraces, FormalParameterNamingConventions, IfElseStmtsMustUseBraces, IfStmtsMustUseBraces, LocalVariableNamingConventions, MethodNamingConventions, MethodWithSameNameAsEnclosingClass, NcssCount, OneDeclarationPerLine, OperationWithHighCostInLoop, OperationWithLimitsInLoop, PropertyNamingConventions, StdCyclomaticComplexity, TooManyFields, WhileLoopsMustUseBraces

Tags: rule_references
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.