
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
49 lines
1.1 KiB
Plaintext
49 lines
1.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Salesforce provides a library of Aggregate functions like COUNT() which efficiently process the data records in the database and return the count of records which meet the SOQL Query criteria. Using size() function instead of COUNT() involves more processing and is less efficient.
|
|
|
|
|
|
This rule raises an issue when the result of an SOQL query is only used to call ``++size()++`` on it.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,apex]
|
|
----
|
|
public class fooClass{
|
|
public static fooMethod {
|
|
integer i = [SELECT Id FROM Case].size(); // Noncompliant
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,apex]
|
|
----
|
|
public class fooClass{
|
|
public static fooMethod {
|
|
integer i = [SELECT COUNT() FROM Case];
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_count.htm[COUNT() and COUNT(fieldName)]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Replace this call to size() with an SOQL count query
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|