只计算记录:
Integer counter = [ Select count()
FROM Payroll_Group_Detail__c
Where Tax_Batch__c = null
And CreatedDate >= 2012-07-21T00:00:00-05:00
And Total_Tax_Amount__c != null ];
System.debug('My counted records: ' + counter);
使用 GROUP BY:
AggregateResult[] aggr = [ Select count(Id)
FROM Payroll_Group_Detail__c
Where Tax_Batch__c = null
And CreatedDate >= 2012-07-21T00:00:00-05:00
And Total_Tax_Amount__c != null
Group By Total_Tax_Amount__c ];
Integer counter = Integer.valueOf(aggr.size());
System.debug('#### counter: ' + counter);
但请记住,您的计数不能超过允许的调控器限制(SOQL 查询检索到的记录总数 -> 50,000)