hardis:datacloud:sql-query
Description
Command Behavior
Executes a SQL query against Salesforce Data Cloud and exports the results.
This command lets you run ad-hoc or predefined SQL queries on Data Cloud objects, view the results in the CLI, and export them for further analysis.
Key functionalities:
- Query input: Accepts inline SQL via
-q, a predefined saved query name, or an interactive prompt when no query is provided. - Test shortcut:
-q testruns a sample query onssot__Account__dlm(sorted by created date, limited to 5000 rows). - Export: Generates CSV and XLSX reports for the returned rows with auto-generated filenames (override with
--outputfile). - Logging: Prints a JSON summary (excluding full records) and supports debug output via
--debug. - Org targeting: Works with the provided or default org connection; respects websocket and skipauth flags.
Technical explanations
The command's technical implementation involves:
- Query resolution:
- If
-qis provided, it is used directly (with a specialtestbranch loading a canned query). - If absent, prompts the user to select from predefined queries on disk (via
listAvailableDataCloudQueries/loadDataCloudQueryFromFile), or enter a custom query. Custom queries can be optionally saved locally (saveDataCloudQueryToFile).
- If
- Execution: Calls
dataCloudSqlQuerywith the resolved SQL against the target org connection. - Output handling: Logs the full result JSON to the terminal; emits a sanitized summary to
uxLog(records removed for readability). - File generation: Uses
generateReportPathto build the output path andgenerateCsvFileto produce CSV/XLSX exports with aDataCloud Sql Query Resultstitle. - CLI UX: Employs
promptsfor interactive selection/input anduxLogfor consistent colored logging with chalk.
Parameters
| Name | Type | Description | Default | Required | Options |
|---|---|---|---|---|---|
| debug -d |
boolean | Activate debug mode (more logs) | |||
| flags-dir | option | undefined | |||
| json | boolean | Format output as json. | |||
| outputfile -f |
option | Force the path and name of output report file. Must end with .csv | |||
| query -q |
option | Data Cloud query string | |||
| skipauth | boolean | Skip authentication check when a default username is required | |||
| target-org -o |
option | undefined | |||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:datacloud:sql-query
$ sf hardis:datacloud:sql-query -q "SELECT ssot__Name__c, ssot__CreatedDate__c FROM ssot__Account__dlm LIMIT 10"
$ sf hardis:datacloud:sql-query -q test