Paging Cookie Pitfalls
Hello everyone.
This time, I would like to introduce some pitfalls that customers have been asking about recently when joining other tables to retrieve more than 5,000 pieces of data.
Incident
It is recommended to use a PagingCookie when retrieving more than 5,000 records using FetchXml.
Also, when joining and retrieving tables with parent-child relationships, you will need to use link-entity to retrieve them, but there are pitfalls in this process.
Let's say you have a record that has one parent record and four child records, as shown below.

To retrieve these records with a page size of 5, write the following FetchXml:
The result obtained is as follows:

The following PagingCookie is also returned:
<親エンティティ主キー項目名 last="b91f4114-fa69-44f4-992e-24b2cc49c726" first="70668a69-9ab9-4017-9bcb-4c841ffbd3f5" />
The PagingCookie contains the first and last values of the primary entity.
If you want to use this PagingCookie to retrieve the second page, write the following FetchXml to retrieve it.
<親エンティティ主キー項目名 last="b91f4114-fa69-44f4-992e-24b2cc49c726" first="70668a69-9ab9-4017-9bcb-4c841ffbd3f5" />
</cookie> version=”1.0″>
The results for the second page will be as follows, meaning that three Parent 2 records were not retrieved.

Proposed solution
This issue occurs because the information stored in the PagingCookie only contains the primary key of the parent record, and does not uniquely identify the joined row.
Therefore, there are three possible solutions:
① Write FetchXml so that the ID of the primary entity is unique
In the case of the primary entity, for example, if you make it a child entity and retrieve data by referencing the parent from the child, the ID of the primary entity will be unique and this issue will no longer occur.
②Do not use paging cookies in the first place
It is possible to retrieve more than 5,000 records without using the paging cookie, so using that method is one option.
However, please note that if you do not use a paging cookie with FetchXml, there are restrictions such as only being able to retrieve up to 50,000 items.
3) Split FetchXml into multiple queries and combine the results in memory
This method involves retrieving the parent and child separately and combining them in memory.
Although this is a reliable method, you need to be careful about performance when implementing it.
The method you choose will depend on how you hold the data, the number of pieces of data, and the type of results you want to obtain, so please consider the method that best suits your needs.
We believe that there are many pitfalls like these that can arise when implementing various systems, so if you are having trouble resolving a problem, please feel free to contact us.
Person who wrote this article
Articles in the same category
-
CRM Usage Guide for NPOs and Nonprofit Organizations — Members, Donors, etc. […] -
CRM Usage Guide for Advertising Agencies — Centralizing Clients and Projects […] -
A CRM Usage Guide for Travel Agencies — Using travel history and preferences to make the next proposal […] -
How to interpret the breakdown of CRM initial costs — How to avoid mistakes in quotes […] -
Differences between CRM 4.0 and personalization -
How to utilize customer data in the AI era — "Quality over quantity" is more important than ever before […]
