Sunday, 3 November 2019

How to get the total record count from an entity in Dynamic CRM

Get Total Count of records in CRM

Description:


In this example we explain that how to count number of records in Dynamic CRM and display it in a form or entity. In this example we explain that how to get total number of contacts in Dynamic CRM.so to get total count records below is the code for that
Code:

int totalCount = 0;
 
 QueryExpression query = new QueryExpression("contact");
 query.ColumnSet = new ColumnSet();
 query.Distinct = true;
 query.ColumnSet.AddColumn("contactid"); 
 query.PageInfo = new PagingInfo();
 query.PageInfo.Count = 5000;
 query.PageInfo.PageNumber = 1;
 query.PageInfo.ReturnTotalRecordCount = true;
 
 EntityCollection entityCollection = orgService.RetrieveMultiple(query);
 totalCount = entityCollection.Entities.Count;
 
 while (entityCollection.MoreRecords)
 {
 query.PageInfo.PageNumber += 1;
 query.PageInfo.PagingCookie = entityCollection.PagingCookie;
 entityCollection = orgService.RetrieveMultiple(query);
 totalCount = totalCount + entityCollection.Entities.Count; 
 } 
 
 MessageBox.Show(totalCount.ToString());



This entry was posted in :

0 comments:

Post a Comment