countQuery(String str)

 Returns the number of records that a dynamic SOQL query would return when executed.

Integer i = Database.countQuery(‘select count() from account’);

System.debug(i);

Note: countQuery will not work if we enter any field inside the count.

count() // ok

count(ID) // error

Our Recent Blog

Share This Post