Activity Forums Salesforce® Discussions Explain difference in COUNT() and COUNT(fieldname) in Salesforce Object Query Language (SOQL).

  • shariq

    Member
    September 22, 2018 at 10:00 pm

    COUNT()

    COUNT() must be the only element in the SELECT list.
    You can use COUNT() with a LIMIT clause.
    You can’t use COUNT() with an ORDER BY clause. Use COUNT(fieldName) instead.
    You can’t use COUNT() with a GROUP BY clause for API version 19.0 and later. Use COUNT(fieldName) instead.

    COUNT(fieldName)

    You can use COUNT(fieldName) with an ORDER BY clause.
    You can use COUNT(fieldName) with a GROUP BY clause for API version 19.0 and later

  • Parul

    Member
    September 23, 2018 at 4:18 am

    COUNT(): It 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.This function returns the number of rows that match the filtering conditions and COUNT() must be the only element in the select list. The resulting query result size field which returns the number of rows and the records will return null.In simple words, COUNT() returns the number of items in a group, including NULL values and duplicates.

    COUNT(fieldname):This function returns the number of rows that match the filtering conditions and have a non-null value records. An Aggregate Result object in the records field contains the number of rows. Do not use the size field for the resulting records.

    Again in simple words, COUNT(expression) evaluates an expression for each row in a group and returns the number of non-null values.

    Note: COUNT(Id) in SOQL is equivalent to COUNT(*) in SQL.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos