Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheContactList does not work for > 5000 contact records. #2

Open
philmoz opened this issue Jun 16, 2015 · 0 comments
Open

CacheContactList does not work for > 5000 contact records. #2

philmoz opened this issue Jun 16, 2015 · 0 comments
Labels

Comments

@philmoz
Copy link

philmoz commented Jun 16, 2015

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;
        }
    }
@brtubb brtubb added the bug label Jun 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants