hardis:org:data:delete
Description
Command Behavior
Deletes records in multiple Salesforce objects using an SFDMU (Salesforce Data Migration Utility) workspace.
This command provides a powerful and controlled way to remove data from your Salesforce orgs based on configurations defined in an SFDMU workspace. It's particularly useful for:
- Data Cleanup: Removing test data, obsolete records, or sensitive information.
- Environment Reset: Preparing sandboxes for new development cycles by clearing specific data sets.
- Compliance: Deleting data to meet regulatory requirements.
Before anything is deleted, the command displays a summary of the objects handled by the workspace (object, operation, external id, filter) followed by the full export.json, then asks for confirmation.
Important Considerations for Production Environments:
If you intend to run this command in a production environment, you must:
- Set
runnableInProductiontotruein yourexport.jsonfile within the SFDMU workspace. - Confirm the modification of the production org when the command asks for it, or, in CI or with
--no-prompt, definesfdmuCanModify: YOUR_INSTANCE_URLin your branch-specific configuration file (e.g.,config/branches/.sfdx-hardis.YOUR_BRANCH.yml) (or theSFDMU_CAN_MODIFYenvironment variable) to explicitly authorize data modification for that instance.
Technical explanations
The command's technical implementation relies heavily on the SFDMU plugin:
- SFDMU Integration: It leverages the
sfdmuplugin to perform the actual data deletion operations. The command acts as a wrapper, providing an assisted interface for SFDMU execution. - Workspace Selection: If the SFDMU workspace path is not provided via the
--pathflag, it interactively prompts the user to select a data workspace usingselectDataWorkspace. - Org Selection: It ensures that a target Salesforce org is selected (either via the
--target-orgflag or through an interactive prompt usingpromptOrgUsernameDefault) to specify where the data deletion will occur. deleteDataUtility: The core logic for executing the SFDMU deletion process is encapsulated within thedeleteDatautility function, which takes the SFDMU workspace path and the target username as arguments.- Environment Awareness: It checks the
isCIflag 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
sfdmuas 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:delete --agent --path ./scripts/data/MyDataProject --target-org myOrg
- The
--pathflag is required in agent mode (no interactive workspace selection). - The
--target-orgflag is used directly (no interactive org selection prompt). - The workspace content is still displayed, but its confirmation prompt is skipped.
Screenshots
Pick the data workspace whose records are deleted
The last confirmation names the org and the data workspace before anything is deleted
The panel batches of the scheduled installations deleted from a scratch org, with a data workspace made for deletion
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 | Import flag values from a directory. | |||
| json | boolean | Format output as json. | |||
| path -p |
option | Path to the sfdmu workspace folder | |||
| skipauth | boolean | Skip authentication check when a default username is required | |||
| target-org -o |
option | Username or alias of the target org. Not required if the target-org configuration variable is already set. |
true | ||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:org:data:delete
$ sf hardis:org:data:delete --agent --path ./scripts/data/MyDataProject --target-org myOrg


