SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Apex

Apex static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your APEX code

  • All rules 97
  • Vulnerability2
  • Bug26
  • Security Hotspot3
  • Code Smell66
Filtered: 22 rules found
salesforce
    Impact
      Clean code attribute
        1. SOQL queries should not contain hardcoded date literals

           Code Smell
        2. Apex classes should contain at most one "@InvocableMethod" annotation

           Bug
        3. SOQL queries should not be executed inside loops

           Code Smell
        4. SOSL queries in test methods should use "Test.setFixedSearchResults"

           Code Smell
        5. DML operations in catch blocks can mask original exceptions

           Bug
        6. Test classes and methods should not use "seeAllData=true"

           Code Smell
        7. HTTP requests should have explicit timeout configuration

           Code Smell
        8. Methods with "@AuraEnabled" should be public or global

           Bug
        9. Classes implementing "Database.Batchable" should be declared as "global"

           Bug
        10. "getRoleAndSubordinates()" should be replaced with "getRoleAndSubordinatesInternal()"

           Code Smell
        11. Future methods making HTTP callouts should include "callout=true" parameter

           Bug
        12. SOQL queries should use SystemModStamp instead of LastModifiedDate for better performance

           Code Smell
        13. Future methods should not call other future methods

           Bug
        14. Test classes should be annotated with "@isTest"

           Code Smell
        15. SOQL queries should include LIMIT clauses to prevent hitting governor limits

           Bug
        16. Private members made public for testing should use "@TestVisible" annotation

           Code Smell
        17. Batch Apex scope parameters should not exceed 2000 records

           Code Smell
        18. Custom event names should not be prefixed with "on"

           Code Smell
        19. Apex REST services should implement comprehensive exception handling

           Vulnerability
        20. SOQL queries should be assigned to Lists to avoid QueryException

           Bug
        21. InvocableMethod annotations should include descriptive label and description

           Code Smell
        22. URLs should not be hardcoded in Apex code

           Bug

        Test classes should be annotated with "@isTest"

        consistency - conventional
        maintainability
        Code Smell
        • salesforce
        • apex
        • test
        • convention

        This rule raises an issue when a class contains test methods but is not annotated with @isTest at the class level.

        Why is this an issue?

        How can I fix it?

        More Info

        In Salesforce, test classes serve a specific purpose and should be properly identified using the @isTest annotation. This annotation provides two key benefits:

        First, it excludes the test class from your organization’s 6MB Apex code storage limit. Without this annotation, test classes count toward your storage quota, which can become problematic as your test suite grows.

        Second, it clearly identifies the class as a test class, making your codebase more maintainable and easier to understand. This explicit marking helps developers quickly distinguish between production code and test code.

        When a class contains test methods (either using the testMethod keyword or methods annotated with @isTest) but lacks the class-level @isTest annotation, it may consume unnecessary storage space and lacks clear identification as a test class.

        What is the potential impact?

        Without the @isTest annotation, test classes count toward your organization’s 6MB Apex code storage limit. This can lead to storage quota issues as your test suite grows, potentially preventing you from deploying new code when the limit is reached.

        Additionally, the lack of clear test class identification makes code maintenance more difficult and can confuse developers about the purpose of the class.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use