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: 1 rule found
readability
    Impact
      Clean code attribute
        1. String conversions should use explicit methods instead of empty string concatenation

           Code Smell

        String conversions should use explicit methods instead of empty string concatenation

        intentionality - clear
        maintainability
        Code Smell
        • performance
        • readability

        This rule raises an issue when values are converted to strings by concatenating them with empty strings ('').

        Why is this an issue?

        How can I fix it?

        More Info

        Converting values to strings by concatenating them with empty strings is an inefficient and unclear practice.

        When you write '' + someValue, the Apex runtime must:

        • Create a temporary string object for the empty string
        • Convert someValue to its string representation
        • Concatenate these two strings
        • Return the result

        This process involves unnecessary object creation and string manipulation overhead.

        Using explicit toString() methods is more efficient because:

        • It directly converts the value to a string without intermediate steps
        • The intent is clearer to other developers reading your code
        • It follows Apex best practices for type conversion

        The performance difference becomes more noticeable when this pattern is used frequently, such as in loops or bulk operations common in Salesforce development.

        What is the potential impact?

        This issue impacts code performance and maintainability:

        • Performance degradation: Unnecessary object creation and string operations can slow down your code, especially in bulk operations
        • Reduced readability: The intent to convert a value to string is less clear when using concatenation
        • Maintenance overhead: Code reviewers and future developers may not immediately understand the purpose of empty string concatenation
          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