This method uses the RetrieveMultiple SDK Method and loops between all the Pages in order to avoid the 5000 records limitation.
private List < Entity > RetrieveMultiple(OrganizationServiceProxy service, QueryExpression query) {
List < Entity > result = new List < Entity > ();
int fetchCount = 5000;
int pageNumber = 1;
query.PageInfo = new PagingInfo();
query.PageInfo.Count = fetchCount;
query.PageInfo.PageNumber = pageNumber;
query.PageInfo.PagingCookie = null;
while (true) {
EntityCollection collections = service.RetrieveMultiple(query);
if (collections.Entities.Count > 0) {
result.AddRange(collections.Entities);
}
if (collections.MoreRecords) {
query.PageInfo.PageNumber++;
query.PageInfo.PagingCookie = collections.PagingCookie;
} else {
break;
}
}
return result;
}
I encourage you to read this text it is fun described ... nonprofit consultants
ReplyDelete