Get Total Count of records in CRM. (more than 5000)


Just sharing a sample code to get the total number of records (e.g. account here)

 IOrganizationService orgService = GetOrganizationService();

 int totalCount = 0;
 QueryExpression query = new QueryExpression("account");
 query.ColumnSet = new ColumnSet();
 query.Distinct = true;
 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; 



Hope it helps

Impersonate a user using the Microsoft Dynamics Web API in Dynamics CRM 2016


A must read post on CRM 2016 ..

Debajit's Dynamic CRM Blog

I have been exploring the Dynamics CRM Web API features and frankly speaking it never ceases to amaze me. So today I am going to explain how you can impersonate a user to create a record from the client side. Wondering how can we impersonate from the client side. After all, till this time, plugins were the privileged objects to do something in impersonation. Well, then Web API has come to shatter many establishments in the CRM society.

I have two users in my CRM system. System Administrator and my account.


I am going to login with the System Administrator account and then create an account on behalf of my account (Debajit Dutta).

Below is the code to do the same.

Let me explain the code a bit here. Here I am creating a account named “Sample Account – Impersonation Test”. However I am creating the record under impersonation. The…

View original post 206 more words

Business Process Error while trying to open records in CRM 2015


Hi we were getting the below error while trying to open any record in CRM 2015


Turned out that by mistake one wrong extra step had got registered on RetrieveMultiple

ActivityFeeds.Plugins: ActivityFeeds.Plugins.ActivityClose]

[c824b80a-d392-e511-8114-3863bb356f90: ActivityFeeds.Plugins.ActivityClose: RetrieveMultiple of any Entity]

Removing this step fixed the issue.

Hope it helps.

Fixed – Microsoft Dynamics CRM Reporting Authoring Extension Setup – Setup cannot continue because there is a pending restart required error in CRM 2015



Got the below error while trying to install the Report Authoring Extension for CRM 2015.

To fix the issue, open the log file, check for the registry path and delete it

Hope it helps !

“Duplicate Column Heading Exists” Error while using Templates for Data Import in CRM 2015



We were getting the Duplicate Column Heading Existing while trying to download template for data import for Opportunity Entity.

Through Customizations we changed the Display Name of the fields that were duplicate and it fixed the issue for us.


I had the same issue.  In Settings> Customizations, display the Entities that causes the error.  Sort the fields by display name and scroll through the list until you find two identical display names.  Rename one, save and publish your changes.  You should now be able to download the Import template.

Do check out this awesome article

Hope it helps ..