Skip to content

hardis:org:data:export

Description

Command Behavior

Exports data from a Salesforce org using an SFDMU (Salesforce Data Migration Utility) project.

This command facilitates the extraction of data from your Salesforce environments based on configurations defined in an SFDMU workspace. It's a powerful tool for various data-related tasks, including:

  • Data Backup: Creating snapshots of your Salesforce data.
  • Data Migration: Extracting data for transfer to another Salesforce org or external system.
  • Reporting and Analysis: Exporting specific datasets for detailed analysis outside of Salesforce.
  • Data Seeding: Preparing data for import into other environments.

Key functionalities:

  • SFDMU Workspace Integration: Leverages an existing SFDMU workspace (defined by an export.json file) to determine which objects and records to export, along with any filtering or transformation rules.
  • Interactive Workspace Selection: If the SFDMU workspace path is not provided via the --path flag, it interactively prompts the user to select one.
  • Org Selection: Ensures that a target Salesforce org is selected (either via the --target-org flag or through an interactive prompt) to specify the source of the data export.
  • Confirmation Before Exporting: Displays a summary of the objects handled by the workspace (object, operation, external id, filter, mocked fields) followed by the full export.json, then asks for confirmation before querying the org.

See this article for a practical example:

How to detect bad words in Salesforce records using SFDX Data Loader and sfdx-hardis

Technical explanations

The command's technical implementation relies heavily on the SFDMU plugin:

  • SFDMU Integration: It acts as a wrapper around the sfdmu plugin, which performs the actual data export operations. The command provides an assisted interface for SFDMU execution.
  • exportData Utility: The core logic for executing the SFDMU export process is encapsulated within the exportData utility function, which takes the SFDMU workspace path and the source username as arguments.
  • Interactive Prompts: Uses selectDataWorkspace to allow the user to choose an SFDMU project and promptOrgUsernameDefault for selecting the source Salesforce org when not running in a CI environment.
  • Environment Awareness: Checks the isCI flag to determine whether to run in an interactive mode (prompting for user input) or a non-interactive mode (relying solely on command-line flags).
  • Required Plugin: It explicitly lists sfdmu as a required plugin, ensuring that the necessary dependency is in place before execution.

Agent Mode

Use --agent to disable all prompts. Typical usage:

sf hardis:org:data:export --agent --path ./scripts/data/MyDataProject --target-org myOrg

  • The --path flag (or --project-name) is required in agent mode (no interactive workspace selection).
  • The --target-org flag is used directly (no interactive org selection prompt).
  • The workspace content is still displayed, but its confirmation prompt is skipped.

Parameters

Name Type Description Default Required Options
agent boolean Run in non-interactive mode for agents and automation
debug
-d
boolean Activate debug mode (more logs)
flags-dir option undefined
json boolean Format output as json.
no-prompt
-r
boolean Do not prompt for Org, use default org
path
-p
option Path to the sfdmu workspace folder
project-name
-n
option Name of the sfdmu project to use (if not defined, you will be prompted to select one)
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:org:data:export
$ sf hardis:org:data:export --project-name MyDataProject --target-org my-org@example.com
$ sf hardis:org:data:export --path ./scripts/data/MyDataProject --no-prompt --target-org my-org@example.com
$ sf hardis:org:data:export --agent --path ./scripts/data/MyDataProject --target-org myOrg

Comments