Query output
sfd query: the row limit, the CSV layout, the output mode for each flag
combination, the sf-compatible --sf-json envelope, and the truncation trailer.
Source: src/ops/query.mjs (the query operation and its paging loop),
src/format.mjs (compactQuery, flattenRecord, toCsv), src/sf-json.mjs
(sfJson.query, sfEnvelope), src/cli/query.mjs (the adapter: request,
render, shouldPrint and after, which print the trailer), src/cli/util.mjs
(queryLimit), and src/cli/constants.mjs (DEFAULT_QUERY_LIMIT, re-exported by
src/commands.mjs). Tests:
test/ops-query-apex.test.mjs (limit paging and slicing), test/format.test.mjs
(toCsv, flattenRecord), test/cli.test.mjs (stdout and stderr by mode,
--limit and --no-limit validation) and test/sf-json.test.mjs.
sfd query "SELECT Id, Name, Owner.Name FROM Account" --csv --limit 200sfd query "SELECT Id FROM Account" --limit 50sfd query "SELECT Id FROM Account" --limit 50 --jsonLimits
- By default, at most 2,000 rows are returned.
--no-limitfetches every page.--limitand--no-limitcannot be combined (exit 2). - Output is compact JSON (
totalSize,done,nextRecordsUrlwhen Salesforce supplies one, andrecordswithattributesstripped). --limit <n>must be a positive safe integer. Anything else is a usage error (exit 2) with--limit must be a positive integer.- Paging stops once at least
nrecords are fetched, and the records are then sliced to exactlyn. NoqueryMorecall is made after that point. - A SOQL
LIMITand--limitcan coexist; the smaller one wins. totalSizestays the server’s total, notn.truncated: trueis set when paging stopped early or records were cut. It is absent otherwise.nextRecordsUrlis kept as Salesforce returned it. It points past the last fetched page. When records were cut by the limit, it does not resume at the row after the last one returned, so rows that were fetched but not shown are skipped. Do not use it to resume a limited query.
Output by mode
| Flags | stdout | stderr |
|---|---|---|
| none | Compact JSON, then the trailer line if truncated | Trace notice, if one was written |
--csv |
CSV only. Nothing at all when there are no rows | Trace notice, if one was written, then the trailer if truncated |
--json |
The daemon response (status, result with truncated) |
Trace notice, if one was written |
--json takes precedence over --csv. It returns the daemon response with
truncated records and the truncated flag, and it prints no trailer.
CSV layout
- The header row lists the union of flattened keys across the returned records, in first-seen order. An empty result has no header, because there are no columns to infer.
- A parent relationship flattens to dotted columns:
Owner.Name, andOwner.Manager.Namefor a deeper parent. - A child subquery becomes compact JSON in one cell, with
attributesstripped (for example[{"Name":"Kid"}]). - A null relationship produces empty cells in the dotted columns of the other rows, not an extra parent column. If every returned row has the relationship null, the parent column is kept with empty cells.
- Quoting follows RFC 4180. A field containing
,,", CR or LF is quoted and embedded quotes are doubled. Numbers and booleans use their JavaScript string form. Null and undefined are empty. Lines end with\n.
Truncation trailer
… 5,011 more rows not shown (totalSize 5,012); raise --limit or narrow the queryFor the implicit default, the hint says use --no-limit for all rows, or narrow the query. Truncation exits 0. The count is totalSize minus the rows
returned, and numbers use en-US separators. In the default mode the line is
written to stdout after the JSON. With --csv it goes to stderr so stdout stays
valid CSV.
Agent hook
The hook rewrites sf data query -q "SELECT Id FROM Account" -r csv to
sfd query 'SELECT Id FROM Account' --csv. --result-format=csv works too.
The human and json result formats are accepted and dropped, as described in
agent-hooks.md. Other result formats are left for sf.
Changing this area
- Keep the paging and truncation rules above in sync with the
queryoperation insrc/ops/query.mjs. The limit-stopping condition, the slicing, and thetruncatedflag all live there. - CSV changes belong in
toCsvorflattenRecordinsrc/format.mjs. Add a case totest/format.test.mjsfor each new rule. - The trailer and output-mode rules are in the
queryadapter (src/cli/query.mjs:render,shouldPrintandafter). Keep the stdout and stderr split as the table describes. Keep the README and the adapter’ssummaryandoptionsin sync. - The default cap is
DEFAULT_QUERY_LIMITinsrc/cli/constants.mjs, and the adapter’s help summary is built from it. The figure 2,000 is also written literally inREADME.md, this file, anddocs/agent-hooks.md, so update those when the constant changes.--sf-jsonis never capped.
sf-compatible JSON
--sf-json requests raw records (including relationship attributes) and
prints {status: 0, result, warnings: []}. A completed query omits
nextRecordsUrl. It bypasses the default row limit and fetches every page,
even beyond sf’s configurable fetch cap. It cannot be combined with --limit,
--csv or --json. Consumed sf data query --json calls use this mode through
the rewrite hook.