You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[apex] ApexSOQLInjection: False positive when passing local var with concatenating strings #2955
If the query is not directly passed as a string literal (or multiple concatenated string literals) but instead as a variable, PMD flags the query as a rule violation when the content of the variable is concatenated.
The issue can be resolved by not passing the query as a variable to Database.query, however, with large queries, this makes the code harder to read (equivalent to calling a method with multiple parameters).
Exception Stacktrace:
No stacktrace.
Code Sample demonstrating the issue:
public without sharing classExampleClass {
publicList<Account> run() {
Stringquery='SELECT Name FROM Account WHERE Active__c = true AND'+' HasSupportPlan__c = true LIMIT 5';
returnDatabase.query(query);
}
publicList<Account> runWithoutRuleViolation() {
returnDatabase.query('SELECT Name FROM Account WHERE Active__c = true AND'+' HasSupportPlan__c = true LIMIT 5');
}
}
This can also be mitigated by replacing Database.query(query) with Database.query(String.escapeSingleQuotes(query)) but that’ll likely create more issues, especially when you’re not using variable binding everywhere.
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
Create the ExampleClass.cls file with the content of the code sample
Run pmd -d ExampleClass.cls -R rulesets/apex/quickstart.xml
See that the output is the following (replace [absolute path] by the path to the ExampleClass.cls). The last point should not be listed because it’s just as secure as the query in runWithoutRuleViolation.
changed the title [-][apex] ApexSOQLInjection false-positive when concatenating strings[/-][+][apex] ApexSOQLInjection: False positive when concatenating strings[/+]on Jun 12, 2026
changed the title [-][apex] ApexSOQLInjection: False positive when concatenating strings[/-][+][apex] ApexSOQLInjection: False positive when passing local var with concatenating strings[/+]on Jun 12, 2026
Activity
[doc] update release notes (pmd#2955)
[-][apex] ApexSOQLInjection false-positive when concatenating strings[/-][+][apex] ApexSOQLInjection: False positive when concatenating strings[/+][-][apex] ApexSOQLInjection: False positive when concatenating strings[/-][+][apex] ApexSOQLInjection: False positive when passing local var with concatenating strings[/+][apex] Fix #2955: ApexSOQLInjection: False positive when concatenatin…