Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

How To : Obtain Reocrds Count Without Retrieving Rows of Data

Leave a comment

Introduction: suppose you want to get records count of the entity type “Account” and you don’t want to rows of data.

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
https://crmprof.wordpress.com/2013/03/13/creating-organization-service-proxy-in-microsoft-dynamics-crm-2011/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s