Search code examples
c#crmdynamics-crm-onlinedynamics-crm-2016dynamics-365

Will this fail if the returned number of records is below 5000?


I have a multirequest for a QueryExpression that I wrote. In some cases, more than five thousand records are returned, while in others less than 5000 records are returned. I am worried that this would fail if the count is less than 5000. Is this true?!

 QueryExpression queryService = conversionResponse.Query;
                int pageNumber = 1;
                RetrieveMultipleRequest multiRequest;
                RetrieveMultipleResponse multiResponse = new RetrieveMultipleResponse();

                do
                {
                    queryService.PageInfo.Count = 5000;
                    queryService.PageInfo.PagingCookie = (pageNumber == 1) ? null : multiResponse.EntityCollection.PagingCookie;
                    queryService.PageInfo.PageNumber = pageNumber++;

                    multiRequest = new RetrieveMultipleRequest
                    {
                        Query = queryService
                    };
                    multiResponse = (RetrieveMultipleResponse)service.Execute(multiRequest);

                    Allergies.Entities.AddRange(multiResponse.EntityCollection.Entities);
                } while (multiResponse.EntityCollection.MoreRecords);

Solution

  • Should be fine in either case.

    There is an MSDN example for something similiar here; Sample: Use QueryExpression with a paging cookie.