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: 3 rules found
soql
    Impact
      Clean code attribute
        1. SOQL queries should not contain hardcoded date literals

           Code Smell
        2. SOQL queries should use SystemModStamp instead of LastModifiedDate for better performance

           Code Smell
        3. SOQL queries should be assigned to Lists to avoid QueryException

           Bug

        SOQL queries should not contain hardcoded date literals

        consistency - conventional
        maintainability
        Code Smell
        • soql
        • salesforce

        This rule raises an issue when a SOQL query contains hardcoded date or datetime literals in WHERE clauses instead of using bind variables or dynamic date calculations.

        Why is this an issue?

        How can I fix it?

        More Info

        Hardcoded date literals in SOQL queries create several maintenance and flexibility problems.

        When you write dates directly in your queries like 2025-06-01T00:00:00Z, you’re creating code that only works for that specific time period. This approach has significant drawbacks:

        Inflexibility: The query can only retrieve data for the exact dates you specified. If you need to query different time periods, you must modify the code each time.

        Maintenance burden: Every time you want to analyze data for a different month, quarter, or year, you need to update the hardcoded values and redeploy your code.

        Testing challenges: It becomes difficult to test your code with different date ranges or to create comprehensive test scenarios that cover various time periods.

        Business logic coupling: Your data access logic becomes tightly coupled to specific dates, making it harder to reuse the same query logic for different business scenarios.

        SOQL provides powerful mechanisms like bind variables and built-in date functions that make queries dynamic and adaptable. Using these features keeps your code flexible and maintainable.

        What is the potential impact?

        Hardcoded date literals make code inflexible and increase maintenance overhead. Every time you need to query different time periods, you must modify and redeploy the code. This approach also makes testing more difficult and couples your queries to specific dates rather than business logic.

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

        © 2025 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use