@simplysf/simply-analytics
Salesforce report and dashboard utilities, starting with converting a report into SOQL
sf plugins install @simplysf/simply-analyticsCommands
Section titled “Commands”sf simply analytics report soql
Section titled “sf simply analytics report soql”Convert a Salesforce report into the SOQL query for the same records.
USAGE $ sf simply analytics report soql [--json] [--flags-dir <value>] [-f <value>] [-r <value>] [-o <value>] [--api-version <value>] [--aggregate] [--strict] [--output-file <value>]
FLAGS -f, --file=<value> Path to a report's .report-meta.xml file. -o, --target-org=<value> Org to read the report from, and to look up field types, custom report types and the running user in. -r, --report=<value> Report in the org to convert: its ID (00O...) or its full name, <FolderDeveloperName>/<ReportDeveloperName>. --aggregate For a summary or matrix report, group the rows as the report does, with a record count and each column's summaries. --api-version=<value> Override the api version used for api requests made by this command --output-file=<value> Write the query to this file instead of standard output. --strict Fail if any part of the report can't be expressed in SOQL, instead of leaving it out with a warning.
GLOBAL FLAGS --flags-dir=<value> Import flag values from a directory. --json Format output as json.
DESCRIPTION Convert a Salesforce report into the SOQL query for the same records.
Reads a report from a `.report-meta.xml` file (`--file`) or from an org (`--report`), and prints the SOQL query that returns the same records: its columns, filters and filter logic, time frame, standard filters, cross filters, groupings and sort.
Standard output gets the query and nothing else, so it can be piped into `sf data query` or saved as a `.soql` file. Anything SOQL can't express, such as a bucket field, a row-level formula or a role hierarchy filter, is left out of the query and listed as a warning on standard error. Use `--strict` to fail instead.
A "My" report (for example, "My opportunities") becomes `OwnerId = '<ID>'`, using the ID of the target org's user, and the command says so on standard error. Without an org, that condition is left out with a warning.
Supported report types: any custom report type, and the standard Opportunities, Accounts, Contacts & Accounts, Leads and Cases report types. Joined reports aren't supported.
For a report from a file, custom report types and custom fields are read from the project the file is in. The target org, when there is one, supplies everything else, such as standard field types: without it, values on fields whose type isn't known are written as text, with a warning.
A summary or matrix report converts to one row per record, ordered by its groupings. Use `--aggregate` to group the rows instead, with `GROUP BY`, a record count, and each column's summaries.
EXAMPLES Convert a report in the project:
$ sf simply analytics report soql --file force-app/main/default/reports/Sales/Open_Pipeline.report-meta.xml
Convert a report in an org, by ID:
$ sf simply analytics report soql --report 00O5e000008AbCdEAF --target-org my-org
Convert a report by its full name, and run the query:
$ sf data query --target-org my-org --query "$(sf simply analytics report soql --report Sales/Open_Pipeline \ --target-org my-org)"
Convert a summary report into a grouped query, and save it:
$ sf simply analytics report soql --report Sales/Pipeline_By_Stage --aggregate --output-file pipeline.soql
Fail if anything can't be converted exactly:
$ sf simply analytics report soql --file force-app/main/default/reports/Sales/Open_Pipeline.report-meta.xml \ --target-org my-org --strict