How To : Obtain Records Count Without Retrieving Rows of Data in CRM Using C# SDK

Brief:

Let's suppose we have a scenario that requires to get only records count of the entity "Account".

Code:

string fetchQuery = @"<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='entity name'>
<attribute name='attribute name' aggregate='count' alias='aliasName'/>
</entity>
</fetch>";

EntityCollection value = _serviceProxy.Execute(new FetchExpression(fetchQuery));

              Returned result will be something as follow:

<resultset morerecords="0"'>
<result>
<aliasName>20</aliasName>
</result>
</resultset>

Note: you can check how to create  Service Proxy at the following link

Leave a Reply

Your email address will not be published. Required fields are marked *