When I originally started working in
As you probably already know, there is a maximum resultset size (5000) in CRM for Fetch queries. You /can/ disable this via a registry setting, but that’s not always feasible (most notably in
In Microsoft Dynamics CRM 2011 the mechanism for invoking Fetch has changed slightly, meaning the previous 4.0 FetchAll() needs some minor updating. Without further ado, here it is. Some of this code may look familiar because it originated from one of those aforementioned blogs.
*Fetch method – this is called by FetchAll to get each successive page.
*Depending on how you structure your code and server connections, service.OrgServiceProxy below will just be whatever your Org Service object is.
*FetchAll method – this checks for a ‘page’ attribute in the fetchXML – if there is not one, it sets it. After each Fetch, it appends the entities to the ‘allRecords’ EntityCollection and increments the Page counter until morerecords = false.
*It might be a little nicer to just have an EntityCollection variable for allRecords instead of a RetrieveMultipleResponse, but at this point I decided to maintain a consistent return type between a regular Fetch and FetchAll. Some of the fields on allRecords (like the ‘morerecords’ and ‘paging’ data are obviously leftover from the first page of results, but those fields are irrelevant with a FetchAll result anyway.)
2 thoughts on “FetchAll() for Microsoft Dynamics CRM 2011 – Handling Large FetchXML Resultsets”
Sorting the unified result set is not really a CRM question but a more general .NET question.
Now that you have a single EntityCollection with an aggregated Entities property, you should be able to use standard .NET sorting approaches for collections. Here are a couple of references that might get you on the right track.
Would it be possile in this way to implement a sorting strategy by multiple criteria? I mean something like a ByNameAndDate strategy?Could you give us an example?
Comments are closed.