COUNT() is an optional clause that can be used in a SELECT statement in a SOQL query to discover the number of rows that a query returns.
In simple words, COUNT() returns the number of items in a group, including NULL values and duplicates.
For example:
SELECT COUNT() FROM Account WHERE Name LIKE 'a%'
SELECT COUNT() FROM Contact, Contact.Account WHERE Account.Name = 'Tester tube'
For COUNT(), the query result size field returns the number of rows. The records field returns null.
Note the following when using COUNT():
- COUNT() must be the only element in the SELECT list. that is you can not add any other field with count()
Read full article from How To Do It In Salesforce: Difference Between Count() And Count(fieldname) In Query Secrets Revealed
No comments:
Post a Comment