Skip to content

Commit 8a2a0de

Browse files
committed
refactor: use autoFetchQuery from sfdx-core instead of maxFetch in dataQuery.ts
1 parent 730ca4f commit 8a2a0de

2 files changed

Lines changed: 5 additions & 77 deletions

File tree

packages/salesforcedx-vscode-soql/src/commands/dataQuery.ts

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -139,36 +139,6 @@ export const dataQuery = Effect.fn('sf.data.query')(function* () {
139139
yield* Effect.promise(() => commandlet.run());
140140
});
141141

142-
/**
143-
* Retrieves the maximum fetch limit from user configuration.
144-
* Checks SF CLI config first, then environment variable, then returns undefined if no limit is set.
145-
*
146-
* @returns Promise resolving to the configured limit number, or undefined if no limit is set.
147-
*/
148-
const getMaxFetch = async (): Promise<number | undefined> => {
149-
try {
150-
// Priority 1: Check SF CLI config value (org-max-query-limit)
151-
const configAggregator = await getSoqlRuntime().runPromise(
152-
Effect.gen(function* () {
153-
const api = yield* getServicesApi;
154-
return yield* api.services.ConfigService.getConfigAggregator();
155-
})
156-
);
157-
const configValue = configAggregator.getPropertyValue<string>('org-max-query-limit');
158-
if (configValue) {
159-
const parsed = parseInt(configValue, 10);
160-
if (!isNaN(parsed) && parsed > 0) {
161-
return parsed;
162-
}
163-
}
164-
} catch {
165-
// If config reading fails, fall back to no limit
166-
}
167-
168-
// No limit configured - return undefined to allow default amount of queries
169-
return undefined;
170-
};
171-
172142
/** Generates table output from query records */
173143
export const generateTableOutput = (records: QueryResult['records'], title: string): string => {
174144
// Ensure the first record exists and is an object
@@ -366,23 +336,6 @@ export const formatFieldValueForDisplay = (value: unknown): string => {
366336
return stringValue.length > 50 ? `${stringValue.substring(0, 47)}...` : stringValue;
367337
};
368338

369-
/**
370-
* Builds query options for the Salesforce connection query method.
371-
* Supports optional maxFetch limit when user has configured query limits.
372-
*
373-
* @param maxFetch - Optional maximum number of records to fetch. If undefined, no limit is applied.
374-
* @returns Query options object with autoFetch and scanAll settings, plus maxFetch if specified.
375-
*/
376-
export const buildQueryOptions = (maxFetch?: number) => {
377-
const baseOptions = {
378-
autoFetch: true,
379-
scanAll: false
380-
};
381-
382-
// Conditionally add maxFetch if user has configured a limit (including 0)
383-
return maxFetch !== undefined ? { ...baseOptions, maxFetch } : baseOptions;
384-
};
385-
386339
/** Displays query results in table format */
387340
export const displayTableResults = (queryResult: QueryResult): void => {
388341
if (!queryResult.records?.length) {
@@ -458,29 +411,14 @@ export const formatErrorMessage = (error: unknown): string => {
458411
};
459412

460413
/**
461-
* Executes a SOQL query using the provided connection (REST or Tooling API).
462-
* Applies user-configured query limits if set, otherwise allows results under Salesforce limits.
414+
* Executes a SOQL query, auto-fetching all pages of results up to the user-configured
415+
* `org-max-query-limit` (default 10,000). Emits a lifecycle warning if results are truncated.
463416
*
464-
* @param connection - Salesforce connection (REST or Tooling API)
417+
* @param connection - Salesforce connection
465418
* @param query - SOQL query string to execute
466-
* @returns Promise resolving to query results with records and metadata
419+
* @param useTooling - Whether to use the Tooling API instead of REST
467420
*/
468421
const runSoqlQuery = async (connection: Connection, query: string, useTooling = false): Promise<QueryResult> => {
469422
channelService.appendLine(nls.localize('data_query_running_query'));
470-
471-
// Get user-configured query limit (if any)
472-
const maxFetch = await getMaxFetch();
473-
474-
// Execute query with appropriate options (with or without maxFetch limit)
475-
const result = await (useTooling ? connection.tooling : connection).query(query, buildQueryOptions(maxFetch));
476-
477-
// Show warning if user-configured limit caused records to be truncated
478-
if (maxFetch !== undefined && result.records.length > 0 && result.totalSize > result.records.length) {
479-
const missingRecords = result.totalSize - result.records.length;
480-
channelService.appendLine(
481-
nls.localize('data_query_warning_limit', missingRecords, maxFetch, result.totalSize, maxFetch)
482-
);
483-
}
484-
485-
return result;
423+
return connection.autoFetchQuery(query, { tooling: useTooling });
486424
};

packages/salesforcedx-vscode-soql/test/jest/commands/dataQuery.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import {
5252
formatFieldValue,
5353
formatFieldValueForDisplay,
5454
generateTableOutput,
55-
buildQueryOptions,
5655
displayTableResults,
5756
convertQueryResultToCSV,
5857
formatErrorMessage
@@ -514,15 +513,6 @@ describe('DataQuery Pure Functions', () => {
514513
});
515514
});
516515

517-
describe('buildQueryOptions', () => {
518-
it('should return base options when maxFetch is undefined', () => {
519-
expect(buildQueryOptions()).toEqual({ autoFetch: true, scanAll: false });
520-
});
521-
it('should include maxFetch when provided', () => {
522-
expect(buildQueryOptions(100)).toEqual({ autoFetch: true, scanAll: false, maxFetch: 100 });
523-
});
524-
});
525-
526516
describe('convertQueryResultToCSV', () => {
527517
it('should return no records message if records are empty', () => {
528518
const result = convertQueryResultToCSV({ records: [], totalSize: 0, done: true });

0 commit comments

Comments
 (0)