Execute a SOSL text-based search query.
Description for data search
Specify the SOSL query at the command line with the --query flag or read the query from a file with the --file flag.
By default, the results are written to the terminal in human-readable format. If you specify --result-format csv, the output is written to one or more CSV (comma-separated values) files. The file names correspond to the Salesforce objects in the results, such as Account.csv. Both --result-format human and --result-format json display only to the terminal.
Flags
| Flag Name (Long) | Flag Name (Short) | Description |
|---|---|---|
| <code>‑‑api‑version</code> | N/A | Type: Value<br><br>Override the api version used for api requests made by this command |
| <code>‑‑file</code> | <code>‑f</code> | Type: Value<br><br>File that contains the SOSL query. |
| <code>‑‑flags‑dir</code> | N/A | Type: Value<br><br>Import flag values from a directory. |
| <code>‑‑json</code> | N/A | Type: Boolean<br><br>Format output as json. |
| <code>‑‑query</code> | <code>‑q</code> | Type: Value<br><br>SOSL query to execute. |
| <code>‑‑result‑format</code> | <code>‑r</code> | Type: Value<br>Valid Values: human, csv, json<br>Default value: human<br><br>Format to display the results, or to write to disk if you specify "csv". |
| <code>‑‑target‑org</code> | <code>‑o</code> | Type: Value<br>Required<br><br>Username or alias of the target org. Not required if the target-org configuration variable is already set. |
Examples for data search
Specify a SOSL query at the command line; the command uses your default org:
sf data search --query "FIND {Anna Jones} IN Name Fields RETURNING Contact (Name, Phone)"
Read the SOSL query from a file called "query.txt"; the command uses the org with alias "my-scratch":
sf data search --file query.txt --target-org my-scratch
Similar to the previous example, but write the results to one or more CSV files, depending on the Salesforce objects in the results:
sf data search --file query.txt --target-org my-scratch --result-format csv
<!-- prettier-ignore-end -->