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.)