Skip to content

Commit

Permalink
Merge pull request #1424 from jsforce/cd/fix-query-missing-batch
Browse files Browse the repository at this point in the history
fix: ensure query stops after reaching max records
  • Loading branch information
shetzel committed May 20, 2024
2 parents 52aeb9a + 11fb447 commit b8eab0f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ export class Query<
this._finished ||
data.done ||
!autoFetch ||
this.records.length === maxFetch ||
// this is what the response looks like when there are no results
(data.records.length === 0 && data.done === undefined);

Expand Down
2 changes: 1 addition & 1 deletion test/connection-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('login', () => {
assert.ok(typeof userInfo.url === 'string');
});

it('should not allow a lightning URL as instance URL', async () => {
it('should not allow a lightning URL as instance URL', () => {
// .lightning
try {
conn = new Connection({
Expand Down
13 changes: 13 additions & 0 deletions test/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ describe('big tables and autoFetch', () => {
assert.ok(records.length === totalRecordCount);
});

it('should return the first batch with autoFetch and maxFetch set to 2000', async () => {
let requestQty = 0

const result = await conn.query(bigTableQuery, { autoFetch: true, maxFetch: 2000}).on('fetch', () => {
requestQty++
})

expect(result.records.length).toBe(2000);
expect(result.nextRecordsUrl).toBeTruthy();
expect(result.done).toBe(false);
expect(requestQty).toBe(1);
});

/**
*
*/
Expand Down

0 comments on commit b8eab0f

Please sign in to comment.