I have a contact entity with more than 5000 records, is there an easy way (other than paging cookie) to find the counts of records?
Asked
Active
Viewed 4,353 times
2 Answers
3
I just found out that there is this plugin called view record counter in XRM toolbox, It solved my problem so no need to use paging cookie. But again this is not ideal as even the plugin takes a few second before it counts even 50K results.

Mohammad Baygi
- 604
- 1
- 7
- 13
2
You can always use FetchXML to get the record count, for example for account:
<fetch aggregate="true" >
<entity name="account" >
<attribute name="accountid" alias="an" aggregate="count" />
</entity>
</fetch>
You can call it like that:
string fetchXml = @"<fetch aggregate='true' >
<entity name='account' >
<attribute name='accountid' alias='accountscount' aggregate='count' />
</entity>
</fetch>";
var results = Service.RetrieveMultiple(new FetchExpression(fetchXml)).Entities;
var count = ((Microsoft.Xrm.Sdk.AliasedValue)results.First()["accountscount"]).Value;
Or use a tool like FetchXMLBuilder to make the call for you

Pawel Gradecki
- 3,476
- 6
- 22
- 37
-
2This works but still there is a limit of 50,000. when I run this in XRM tool box it returns an error saying AggregateQueryRecordLimit exceeded. In my case I have arround 550 K records so this method does not work. – Mohammad Baygi Nov 08 '17 at 03:22