LinuxCommandLibrary

sfdk-undeploy

Undeploy Solutions Enabler server-based functionalities

TLDR

Undeploy using a specified method (pkcon, rpm, rsync, sdk or zypper)

$ sfdk undeploy --[method]
copy

Preview undeploy without applying the changes
$ sfdk undeploy --[method] [[-n|--dry-run]]
copy

Undeploy files in glob pattern package*
$ sfdk undeploy --[method] "+package*"
copy

Undeploy all files excluding ignore*
$ sfdk undeploy --[method] "-ignore*"
copy

SYNOPSIS

sfdx undeploy:metadata -m -o sfdx undeploy:package -p -o sfdx undeploy:destructive -f -o

PARAMETERS

-m, --metadata
    Specifies the metadata type and component name to undeploy (e.g., `CustomObject:MyCustomObject`). Multiple components can be specified by repeating the parameter.

-p, --package
    Specifies a package (directory) containing metadata to be undeployed. The plugin will generate a destructiveChanges.xml file based on the package contents.

-f, --destructiveChangesFile
    Specifies the path to an existing `destructiveChanges.xml` file to use for undeployment.
Warning: Use with extreme caution, destructive operation!.

-o, --targetusername
    Specifies the target Salesforce org to undeploy from. Can be an alias or username. Defaults to the default org if not specified.

--apiversion
    Specifies the API version to use for the undeployment. If not specified, the default API version for the SFDX CLI is used.

-w, --wait
    Number of minutes to wait for the deployment process to complete. Default: 33 minutes.

--json
    Format output as JSON.

--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL
    Logging level for this command invocation. Runs with logging level warning if run from an automated process like a script or CI.

DESCRIPTION

The `sfdx-undeploy` plugin for Salesforce DX (SFDX) CLI provides commands for selectively undeploying metadata components from a Salesforce org. Unlike a full destructive changes deployment using the Metadata API, `sfdx-undeploy` allows you to remove specific components without needing a complete manifest. This is useful for removing components created during development or for cleaning up environments. The plugin leverages the Salesforce Metadata API internally, but simplifies the process by offering easier command syntax and better control over which metadata types and members are targeted for removal. It primarily uses the `destructiveChanges.xml` file behind the scenes, but offers options to generate it dynamically or directly specify the components to delete through command line parameters.

CAVEATS

Undeployment is a destructive operation. Ensure you have backups or source control before using this plugin. Incorrect usage can lead to permanent data loss or corruption of your Salesforce org. Some metadata types cannot be undeployed. Carefully review the Salesforce Metadata API documentation for limitations.

USAGE EXAMPLES

Undeploy a single custom object:
`sfdx undeploy:metadata -m CustomObject:MyCustomObject -o MyDevOrg`

Undeploy components based on a package directory:
`sfdx undeploy:package -p ./my_package -o MyDevOrg`

Undeploy using a destructiveChanges.xml file:
`sfdx undeploy:destructive -f ./destructiveChanges.xml -o MyDevOrg`

DESTRUCTIVE CHANGES FILE

The destructiveChanges.xml file is a standard Salesforce Metadata API file used to specify components for deletion. It contains a list of metadata types and their member names to remove from the org.
Note: Always back up your metadata and carefully review the contents of the destructiveChanges.xml file before executing the undeploy command.

SEE ALSO

sfdx force:mdapi:deploy(1), sfdx force:source:deploy(1)

Copied to clipboard