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
 
Tags
    Impact
      Clean code attribute
        1. Apex classes should contain at most one "@InvocableMethod" annotation

           Bug
        2. DML operations in catch blocks can mask original exceptions

           Bug
        3. Future methods must be static and return void

           Bug
        4. Test classes should have only one @testSetup method

           Bug
        5. Methods with "@AuraEnabled" should be public or global

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

           Bug
        7. Future methods making HTTP callouts should include "callout=true" parameter

           Bug
        8. Future methods should not call other future methods

           Bug
        9. SOQL queries should include LIMIT clauses to prevent hitting governor limits

           Bug
        10. SOQL queries should be assigned to Lists to avoid QueryException

           Bug
        11. Test methods should not have parameters

           Bug
        12. URLs should not be hardcoded in Apex code

           Bug
        13. "@future" methods should not be called in loops

           Bug
        14. Email messages should be sent in batches

           Bug
        15. URLs of Salesforce pages should be relative, not absolute.

           Bug
        16. "getRecordTypeInfosByDeveloperName()" should be used instead of "getRecordTypeInfosByName()"

           Bug
        17. DML statements should not be used inside loops

           Bug
        18. Record IDs should not be hardcoded

           Bug
        19. Triggers should process records in bulk

           Bug
        20. All branches in a conditional structure should not have exactly the same implementation

           Bug
        21. Non-existent operators like "=+" should not be used

           Bug
        22. Related "if"/"else if" statements and "when" in a "switch" should not have the same condition

           Bug
        23. Identical expressions should not be used on both sides of a binary operator

           Bug
        24. All code should be reachable

           Bug
        25. Variables should not be self-assigned

           Bug
        26. Useless "if(true) {...}" and "if(false){...}" blocks should be removed

           Bug

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

        intentionality - logical
        reliability
        Bug
        • apex
        • salesforce

        This is an issue when a class implements the Database.Batchable interface but is not declared with the global access modifier.

        Why is this an issue?

        How can I fix it?

        More Info

        In Salesforce, batch classes must be accessible by the platform’s batch processing framework to execute properly. The Database.Batchable interface is designed for processing large volumes of data asynchronously.

        When you implement Database.Batchable, the Salesforce platform needs to instantiate and call your class methods (start, execute, and finish) during batch execution. If your class is declared as public instead of global, the platform cannot access it from outside your namespace.

        This restriction exists because:

        • The batch processing framework runs in the system context
        • It needs cross-namespace access to your batch class
        • Only global classes can be accessed across different namespaces in Salesforce

        Without the global modifier, your batch job will fail to execute, even though the code compiles successfully. This can lead to silent failures where scheduled batches simply don’t run.

        What is the potential impact?

        The batch job will fail to execute, preventing the processing of large datasets. This can cause:

        • Data processing delays or complete failures
        • Scheduled operations that silently don’t run
        • Business processes that depend on batch processing to malfunction
        • Difficulty in debugging since the error may not be immediately apparent
          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