Tip #1375: Get record count for entities

I need to perform some data… uhm… “augmentation”. Easy as using Power Automate – get all the records, loop through, fudge I mean augment the data. Right? Except there could be more than 100,000 records. Why 100K? That’s the maximum you can get with the List Records action. (Wanted to insert a reference here but that limit does not seem to be documented at all… Oh, well, save it for another tip). In short: I need quickly to find out the total number of records in couple entities. On top of that, those were the entities not exposed outside of their parent entities, like Order Product or Invoice Product.

Even if you are not a developer there are couple Web API methods you can add to your toolbox and RetrieveTotalRecordCount function is one of them.

https://orgname.crmN.dynamics.com/api/data/v9.1/RetrieveTotalRecordCount(EntityNames=['logical_name_1','logical_name_2', ...])

for example:

https://foobar.crm.dynamics.com/api/data/v9.1/RetrieveTotalRecordCount(EntityNames=['salesorder','salesorderdetail','invoice','invoicedetail'])

This is what comes back:

{
  "@odata.context": "https://foobar.crm.dynamics.com/api/data/v9.1/$metadata#Microsoft.Dynamics.CRM.RetrieveTotalRecordCountResponse",
  "EntityRecordCountCollection": {
    "Count": 4,
    "IsReadOnly": false,
    "Keys": [
      "salesorder",
      "salesorderdetail",
      "invoice",
      "invoicedetail"
    ],
    "Values": [
      6679,
      10547,
      17568,
      59618
    ]
  }
}

Nice and easy, right?

Cover photo by Amornthep Srina from Pexels.

4 thoughts on “Tip #1375: Get record count for entities

  1. endeared says:

    when delete or create record,the count api result looks like can’t be updated immediately.is it a api bug?

  2. Santosh Kumar Korada says:

    Hi ,

    Here we are getting the total record count , what if we have want count of records created on specific date . Could you please help me on this

Leave a Reply

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