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 56
  • Vulnerability1
  • Bug12
  • Security Hotspot3
  • Code Smell40
Filtered: 2 rules found
governor-limits
    Impact
      Clean code attribute
        1. Tested code should be enclosed between "Test.StartTest()" and "Test.StopTest()"

           Code Smell
        2. DML statements should not be used inside loops

           Bug

        Tested code should be enclosed between "Test.StartTest()" and "Test.StopTest()"

        adaptability - tested
        maintainability
        Code Smell
        • governor-limits

        Why is this an issue?

        More Info

        In order to protect shared resources, Salesforce enforces a maximum number of SOQL queries, DML queries, @future method, etc…​ execution inside a single transaction. This is part of Governor limits.

        Every test method should check how close the tested code is to reach the governor limits. This is done by calling Test.StartTest() before the tested code and Test.StopTest() after it.

        This rule raises an issue when a test method, i.e. a method annotated with @isTest or testmethod, does not contain a call to Test.StartTest() and Test.StopTest().

        Noncompliant code example

        @isTest()
        public class MyTestClass {
            @isTest()
            static void myTestMethod() { // Noncompliant
                // Preparing test (creating records, etc...)
                // test code with no reference to Test.StartTest() or Test.StopTest()
            }
        
            static testmethod void myTestMethod2() { // Noncompliant
                // Preparing test (creating records, etc...)
                // test code with no reference to Test.StartTest() or Test.StopTest()
            }
        
            static void myHelper() {
                // ...
            }
        }
        

        Compliant solution

        @isTest()
        public class MyTestClass {
            @isTest()
            static void myTestMethod() {
                // Preparing test (creating records, etc...)
                Test.StartTest();
                // test code with no reference to Test.StartTest() or Test.StopTest()
                Test.StopTest();
            }
        
            static testmethod void myTestMethod2() {
                // Preparing test (creating records, etc...)
                Test.StartTest();
                // test code with no reference to Test.StartTest() or Test.StopTest()
                Test.StopTest();
            }
        
            static void myHelper() {
                // ...
            }
        }
        

        Exceptions

        No issue will be raised if the test class, i.e. the class annotated with @isTest, contains helper methods, i.e. methods not annotated with @isTest or testmethod, which contain calls to Test.StartTest() or Test.StopTest(). This indicates that the test code has been factorised and the rule would raise false positives.

          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Enterprise
          Edition
          Available Since
          9.1

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use