locked
does retrievemultiple page at 5000 records and, if so, how do I get the next page? RRS feed

  • Question

  • I'm looking for c# code example for processing all records when the count is greater than 5000.
    Wednesday, March 26, 2014 7:56 PM

Answers

  • Check out this example from the SDK: Page Large Result Sets with Query Expression


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, March 26, 2014 8:16 PM
    Moderator
  • This is the code I use:

                EntityCollection retrievedRecords = new EntityCollection();
                QueryExpression contactQuery = new QueryExpression
                {
                    EntityName = "contact",
                    ColumnSet = new ColumnSet(true),
                    Criteria = new FilterExpression()
                };
    
                // you can add criteria
                contactQuery.Criteria.AddCondition("firstname", ConditionOperator.Equal, "john");
    
                int pageNumber = 1;
                RetrieveMultipleRequest multiRequest;
                RetrieveMultipleResponse multiResponse = new RetrieveMultipleResponse();
    
                do
                {
                    contactQuery.PageInfo.Count = 5000;
                    contactQuery.PageInfo.PagingCookie = (pageNumber == 1) ? null : multiResponse.EntityCollection.PagingCookie;
                    contactQuery.PageInfo.PageNumber = pageNumber++;
    
                    multiRequest = new RetrieveMultipleRequest();
                    multiRequest.Query = contactQuery;
                    multiResponse = (RetrieveMultipleResponse)service.Execute(multiRequest);
    
                    retrievedRecords.Entities.AddRange(multiResponse.EntityCollection.Entities);
                }
                while (multiResponse.EntityCollection.MoreRecords);
                // now retrievedRecords contains all the records


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Wednesday, March 26, 2014 8:19 PM

All replies

  • Check out this example from the SDK: Page Large Result Sets with Query Expression


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, March 26, 2014 8:16 PM
    Moderator
  • This is the code I use:

                EntityCollection retrievedRecords = new EntityCollection();
                QueryExpression contactQuery = new QueryExpression
                {
                    EntityName = "contact",
                    ColumnSet = new ColumnSet(true),
                    Criteria = new FilterExpression()
                };
    
                // you can add criteria
                contactQuery.Criteria.AddCondition("firstname", ConditionOperator.Equal, "john");
    
                int pageNumber = 1;
                RetrieveMultipleRequest multiRequest;
                RetrieveMultipleResponse multiResponse = new RetrieveMultipleResponse();
    
                do
                {
                    contactQuery.PageInfo.Count = 5000;
                    contactQuery.PageInfo.PagingCookie = (pageNumber == 1) ? null : multiResponse.EntityCollection.PagingCookie;
                    contactQuery.PageInfo.PageNumber = pageNumber++;
    
                    multiRequest = new RetrieveMultipleRequest();
                    multiRequest.Query = contactQuery;
                    multiResponse = (RetrieveMultipleResponse)service.Execute(multiRequest);
    
                    retrievedRecords.Entities.AddRange(multiResponse.EntityCollection.Entities);
                }
                while (multiResponse.EntityCollection.MoreRecords);
                // now retrievedRecords contains all the records


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Wednesday, March 26, 2014 8:19 PM
  • I concur that these are answers.  Not quick enough on the trigger I guess.
    Tuesday, April 8, 2014 9:45 PM