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
public class fooClass{
public static fooMethod {
integer i = [SELECT Id FROM Case].size(); // Noncompliant
}
}
Compliant solution
public class fooClass{
public static fooMethod {
integer i = [SELECT COUNT() FROM Case];
}
}