odatadynamics-crmdynamics-crm-onlinedynamics-crm-365dynamics-crm-webapi

Counting ALL rows in Dynamics CRM Online web api (ODATA)


Is it possible to count all rows in a given entity, bypassing the 5000 row limit and bypassing the pagesize limit?

I do not want to return more than 5000 rows in one request, but only want the count of all the rows in that given entity.

According to Microsoft, you cannot do it in the request URI:

The count value does not represent the total number of entities in the system. 

It is limited by the maximum number of entities that can be returned.

I have tried this:

GET [Organization URI]/api/data/v9.0/accounts/?$count=true

Any other way?


Solution

  • Use function RetrieveTotalRecordCount:

    If you want to retrieve the total number of records for an entity beyond 5000, use the RetrieveTotalRecordCount Function.

    Your query will look like this:

    https://<your api url>/RetrieveTotalRecordCount(EntityNames=['accounts'])