Metadata listing
sfd list-metadata-types and sfd list-metadata: the supported type list and
its daemon cache, how member listings are queried, folder-based types, unknown
type suggestions, output formats and the --json shape. Source:
src/org-session.mjs (metadataTypes, and the typeCache clears in invalidate),
src/sf-util.mjs (metadataSuggestion), src/ops/list-metadata-types.mjs,
src/ops/list-metadata.mjs, src/format.mjs (formatMetadataTypes, formatMetadataList),
the list-metadata-types and list-metadata adapters in src/cli/ (their
--folder and --details options), and
src/rewrite.mjs (the org list metadata-types and org list metadata
mappings). Tests: test/ops-metadata.test.mjs, test/org-session.test.mjs (the metadata cache),
test/format.test.mjs, test/cli.test.mjs, test/rewrite.test.mjs, and the
opt-in real-org case in test/org.test.mjs (needs SFD_TEST_ORG).
sfd list-metadata-typessfd list-metadata -m Flow,Layoutsfd list-metadata -m Report --folder Public_Reports --detailsType list and cache
listMetadataTypescallsconn.metadata.describe(apiVersion)and keeps eachmetadataObjectsentry as{ name: xmlName, inFolder, children }, sorted by name. Child names are flattened to an array.- The cache is in daemon memory. It is keyed by org alias, then by the connection’s API version. A pending describe is stored, so simultaneous callers share one request. A failed describe is removed, so the next call retries.
- The cache is cleared for every org when the auth stamp changes or on
sfd reload. It is cleared for the affected username’s aliases whenwithConnsees a session error (INVALID_SESSION_IDorINVALID_AUTH_HEADER), whether or not the call is retried. Both paths go throughinvalidate. The auth stamp covers the.sfdxJSON filenames and the alias and config files in~/.sfand~/.sfdx. Changes to the contents of an existing.sfdxJSON file, including token refreshes, do not clear caches. See auth-cache.md. - The JSON result includes
cached, which istruewhen the type list was already in memory. - Member lists are never cached. Every
list-metadatacall is live.
Member listing
listMetadata runs in this order. Nothing is listed until every check passes.
-mis required, and repeated or comma-separated types are de-duplicated.--folderwith more than one type is a usage error.- Each type must be in the cached type list. Child type names count, because
describe advertises them. Whether the Metadata API accepts a given child type
in
listMetadatais up to the server. - For an unknown type, the error names it and adds
Did you mean <Name>?when a suggestion exists. A known name that starts with the input (case-insensitive) wins. Otherwise the closest name within Levenshtein distance 2 is used. - Each type becomes one query. A folder-based type (
inFolder) with no--folderqueries its folder type instead:<Type>Folder.EmailTemplateusesEmailTemplateFolderwhen describe advertises it, andEmailFolderotherwise. That group is markedfoldersand gets a hint. With--folder, the query is{ type, folder }for the type itself. conn.metadata.listaccepts at most three queries per call. Queries are split into chunks of three, with at most two chunks running at once.- The response is normalized with
asArray, because the server may return nothing, one object or an array. Members are matched to their group bytypeand sorted byfullName. Each member keepsfullName,lastModifiedDate,lastModifiedByName,namespacePrefixandmanageableState.
Without --folder, a folder-based type lists folders only. To list the members
of one folder, pass --folder <name>. Listing every folder at once is not
supported.
Output
formatMetadataTypes:
- Header:
N metadata types (API vXX.0). - One line per type:
Name, then(folder)for folder-based types, then[child, child, …+N]when children exist. At most six children are shown.
formatMetadataList:
- One group, not a folder group, without
--details: bare names, one per line. - Several groups: a
Type (N):header for each group, with names indented by two spaces. - A folder group:
<FolderType> (N): use --folder <name> to list members, followed by the folder names. --detailsjoins the name with the optional fields, separated by two spaces:fullName YYYY-MM-DD modifier ns:<prefix> <manageableState>. Empty fields are omitted, and the date is cut toYYYY-MM-DD.- An empty group prints
(none).
Exit codes: 0 on success. Usage errors (missing -m, --folder with several
types, unknown type) exit 2. A Salesforce failure exits 1. A daemon failure
exits 3.
JSON
--json prints the raw response. The result for list-metadata-types has
types, apiVersion and cached. The result for list-metadata has groups.
Each group has type, members (with the fields above), and, for a folder
group, folders: true and folderType.
Rewrite hook
sf org list metadata-typesmaps tolist-metadata-types.sf org list metadata -m|--metadata-type <Type> [--folder <name>]maps tolist-metadata. Without-m, the rewriter skips the command.--api-version,-fand--output-fileare unsupported on both commands, so the rewriter skips them. The table in agent-hooks.md lists the rest.
Limits
- No member caching, no
package.xmlgeneration, and no listing of all folders at once. - Standard value sets and other special cases are not listed separately. The
output covers what
listMetadatareturns.
Keeping it in sync
- Changes to the cache belong in
src/org-session.mjs; batching and folder rules belong insrc/ops/list-metadata.mjs. Update this file and their tests together. - A new listing option needs an entry in the adapter’s
options, a usage check insrc/ops/list-metadata.mjs, a README row, and a rewrite entry whensfhas an equivalent. Keep the adapter’sagentTipin step with the snippet (see agents-snippet.md).