-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
The code in CacheContactList (SessionManager.cs) is not setting the PagingCookie on the QueryExpression for the 2nd and subsequent queries when there are > 5000 contact records in CRM.
The following code works for me.
public static void CacheContactList()
{
var moreRecords = true;
var allContactsList = new List<Entity>();
//query expression
var qe = new QueryExpression(ContactLogicalName)
{
ColumnSet = new ColumnSet(CrmContactLookupFields.ToArray()),
PageInfo = new PagingInfo
{
PageNumber = 1,
}
};
while (moreRecords)
{
EntityCollection ents = null;
Pool.Perform(xrm => { ents = xrm.RetrieveMultiple(qe); });
allContactsList.AddRange(ents.Entities);
moreRecords = ents.MoreRecords; //check to see if we have more records in the system
if (moreRecords)
{
qe.PageInfo.PageNumber++;
qe.PageInfo.PagingCookie = ents.PagingCookie;
}
}
//replace the current cached list with the updated list
//this ensures old contacts that were deleted are not included anymore
lock (_cachedContacts)
{
_cachedContacts = allContactsList;
}
}
Reactions are currently unavailable