diff --git a/packages/twenty-front/src/modules/object-record/hooks/useLazyFetchAllRecords.ts b/packages/twenty-front/src/modules/object-record/hooks/useLazyFetchAllRecords.ts index c8dfbbe49..483c36f1e 100644 --- a/packages/twenty-front/src/modules/object-record/hooks/useLazyFetchAllRecords.ts +++ b/packages/twenty-front/src/modules/object-record/hooks/useLazyFetchAllRecords.ts @@ -94,9 +94,9 @@ export const useLazyFetchAllRecords = ({ const rawResult = await fetchMoreRecordsLazy(); - const fetchMoreResult = rawResult?.data?.[objectMetadataItem.namePlural]; + const fetchMoreResult = rawResult?.data; - for (const edge of fetchMoreResult.edges) { + for (const edge of fetchMoreResult?.edges ?? []) { records.push(edge.node); } @@ -106,11 +106,11 @@ export const useLazyFetchAllRecords = ({ displayType: totalCount ? 'percentage' : 'number', }); - if (fetchMoreResult.pageInfo.hasNextPage === false) { + if (fetchMoreResult?.pageInfo.hasNextPage === false) { break; } - lastCursor = fetchMoreResult.pageInfo.endCursor ?? null; + lastCursor = fetchMoreResult?.pageInfo.endCursor ?? null; } setIsDownloading(false);