mdapi Commands
force:mdapi:convert
Help for force:mdapi:convert
To use Salesforce CLI to work with components that you retrieved via Metadata API, first convert your files from the metadata format to the source format using "sfdx force:mdapi:convert".
To convert files from the source format back to the metadata format, so that you can deploy them using "sfdx force:mdapi:deploy", run "sfdx force:source:convert".
Examples:
1$ sfdx force:mdapi:convert -r path/to/metadata1$ sfdx force:mdapi:convert -r path/to/metadata -d path/to/outputdirCommand Syntax
- sfdx force:mdapi:convert
- [--json]
- [--loglevel LOGLEVEL]
- -r ROOTDIR
- [-d OUTPUTDIR]
- [-x MANIFEST]
- [-m METADATA]
- [-p METADATAPATH]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -r | --rootdir ROOTDIR
- Required
-
The root directory that contains the metadata you retrieved using Metadata API.
- Type: directory
- -d | --outputdir OUTPUTDIR
- Optional
-
The directory to store your files in after they’re converted to the source format. Can be an absolute or relative path.
- Type: directory
- -x | --manifest MANIFEST
- Optional
-
The complete path to the manifest (package.xml) file that specifies the metadata types to convert.
If you specify this parameter, don’t specify --metadata or --sourcepath.
- Type: string
- -m | --metadata METADATA
- Optional
-
A comma-separated list of metadata component names to convert.
- Type: array
- -p | --metadatapath METADATAPATH
- Optional
-
A comma-separated list of paths to the local source files to convert. The supplied paths can be to a single file (in which case the operation is applied to only one file) or to a folder (in which case the operation is applied to all metadata types in the directory and its sub-directories).
If you specify this parameter, don’t specify --manifest or --metadata.If the comma-separated list you’re supplying contains spaces, enclose the entire comma-separated list in one set of double quotes.
- Type: array
force:mdapi:deploy
Help for force:mdapi:deploy
Specify the location of the files to deploy as a .zip file or by the root of the directory tree containing the files. To check the status of a deployment, specify its job ID. To run quick deploy of a recently validated package, use --validateddeployrequestid with the validated ID.
To wait for the command to finish running no matter how long the deployment takes, set --wait to -1: "sfdx force mdapi:deploy -w -1 ...".
Command Syntax
- sfdx force:mdapi:deploy
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- [-c]
- [-d DEPLOYDIR]
- [-w WAIT]
- [-l TESTLEVEL]
- [-r RUNTESTS]
- [-o]
- [-g]
- [-q VALIDATEDDEPLOYREQUESTID]
- [--verbose]
- [-f ZIPFILE]
- [-s]
- [--soapdeploy]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -c | --checkonly
- Optional
-
Validates the deployed metadata and runs all Apex tests, but prevents the deployment from being saved to the org.
If you change a field type from Master-Detail to Lookup or vice versa, that change isn’t supported when using the --checkonly parameter to test a deployment (validation). This kind of change isn’t supported for test deployments to avoid the risk of data loss or corruption. If a change that isn’t supported for test deployments is included in a deployment package, the test deployment fails and issues an error.
If your deployment package changes a field type from Master-Detail to Lookup or vice versa, you can still validate the changes prior to deploying to Production by performing a full deployment to another test Sandbox. A full deployment includes a validation of the changes as part of the deployment process.
Note: A Metadata API deployment that includes Master-Detail relationships deletes all detail records in the Recycle Bin in the following cases.
1. For a deployment with a new Master-Detail field, soft delete (send to the Recycle Bin) all detail records before proceeding to deploy the Master-Detail field, or the deployment fails. During the deployment, detail records are permanently deleted from the Recycle Bin and cannot be recovered.
2. For a deployment that converts a Lookup field relationship to a Master-Detail relationship, detail records must reference a master record or be soft-deleted (sent to the Recycle Bin) for the deployment to succeed. However, a successful deployment permanently deletes any detail records in the Recycle Bin.
- Type: boolean
- -d | --deploydir DEPLOYDIR
- Optional
-
The root of the directory tree that contains the files to deploy. The root must contain a valid package.xml file describing the entities in the directory structure. Required to initiate a deployment if you don’t use --zipfile. If you specify both --zipfile and --deploydir, a zip file of the contents of the --deploydir directory is written to the location specified by --zipfile.
- Type: directory
- -w | --wait WAIT
- Optional
-
The number of minutes to wait for the command to complete. The default is –1 (no limit). 0
- Type: minutes
- -l | --testlevel TESTLEVEL
- Optional
-
Specifies which level of deployment tests to run. Valid values are:
NoTestRun—No tests are run. This test level applies only to deployments to development environments, such as sandbox, Developer Edition, or trial orgs. This test level is the default for development environments.
RunSpecifiedTests—Runs only the tests that you specify in the --runtests option. Code coverage requirements differ from the default coverage requirements when using this test level. Executed tests must comprise a minimum of 75% code coverage for each class and trigger in the deployment package. This coverage is computed for each class and trigger individually and is different than the overall coverage percentage.
RunLocalTests—All tests in your org are run, except the ones that originate from installed managed packages. This test level is the default for production deployments that include Apex classes or triggers.
RunAllTestsInOrg—All tests in your org are run, including tests of managed packages.
If you don’t specify a test level, the default behavior depends on the contents of your deployment package. For more information, see “Running Tests in a Deployment” in the Metadata API Developer Guide.
- Type: enum
- Permissible values are: NoTestRun, RunSpecifiedTests, RunLocalTests, RunAllTestsInOrg
- -r | --runtests RUNTESTS
- Optional
-
Lists the Apex classes containing the deployment tests to run. Use this parameter when you set --testlevel to RunSpecifiedTests.
- Type: array
- -o | --ignoreerrors
- Optional
-
Ignores the deploy errors, and continues with the deploy operation. The default is false. Keep this parameter set to false when deploying to a production org. If set to true, components without errors are deployed, and components with errors are skipped.
- Type: boolean
- -g | --ignorewarnings
- Optional
-
If a warning occurs and ignoreWarnings is set to true, the success field in DeployMessage is true. When ignoreWarnings is set to false, success is set to false, and the warning is treated like an error.
This field is available in API version 18.0 and later. Prior to version 18.0, there was no distinction between warnings and errors. All problems were treated as errors and prevented a successful deployment.
- Type: boolean
- -q | --validateddeployrequestid VALIDATEDDEPLOYREQUESTID
- Optional
-
Specifies the ID of a package with recently validated components to run a Quick Deploy. Deploying a validation helps you shorten your deployment time because tests aren’t rerun. If you have a recent successful validation, you can deploy the validated components without running tests. A validation doesn’t save any components in the org. You use a validation only to check the success or failure messages that you would receive with an actual deployment. To validate your components, add the -c | --checkonly flag when you run "sfdx force:mdapi:deploy". This flag sets the checkOnly="true" parameter for your deployment. Before deploying a recent validation, ensure that the following requirements are met:
1. The components have been validated successfully for the target environment within the last 10 days.
2. As part of the validation, Apex tests in the target org have passed.
3. Code coverage requirements are met.
- If all tests in the org or all local tests are run, overall code coverage is at least 75%, and Apex triggers have some coverage.
- If specific tests are run with the RunSpecifiedTests test level, each class and trigger that was deployed is covered by at least 75% individually.
- Type: id
- --verbose
- Optional
-
Indicates that you want verbose output from the deploy operation.
- Type: boolean
- -f | --zipfile ZIPFILE
- Optional
-
The path to the .zip file of metadata files to deploy. You must indicate this option or --deploydir.If you specify both --zipfile and --deploydir, a .zip file of the contents of the deploy directory is created at the path specified for the .zip file.
- Type: filepath
- -s | --singlepackage
- Optional
-
Indicates that the specified .zip file points to a directory structure for a single package. By default, the CLI assumes the directory is structured for a set of packages.
- Type: boolean
- --soapdeploy
- Optional
-
Deploy metadata with SOAP API instead of the default REST API. Because SOAP API has a lower .ZIP file size limit (400 MB uncompressed, 39 MB compressed), Salesforce recommends REST API deployment. This flag provides backwards compatibility with API version 50.0 and earlier when deploy used SOAP API by default.
- Type: boolean
force:mdapi:deploy:cancel
Help for force:mdapi:deploy:cancel
Use this command to cancel a specified asynchronous metadata deployment. You can also specify a wait time (in minutes) to check for updates to the canceled deploy status.
Examples:
Deploy a directory of files to the org
1$ sfdx force:mdapi:deploy -d <directory>Now cancel this deployment and wait two minutes
1$ sfdx force:mdapi:deploy:cancel -w 2If you have multiple deployments in progress and want to cancel a specific one, specify the job ID
1$ sfdx force:mdapi:deploy:cancel -i <jobid>Check the status of the cancel job
1$ sfdx force:mdapi:deploy:reportCommand Syntax
- sfdx force:mdapi:deploy:cancel
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- [-w WAIT]
- [-i JOBID]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -w | --wait WAIT
- Optional
-
Number of minutes to wait for the command to complete and display results to the terminal window. If the command continues to run after the wait period, the CLI returns control of the terminal window to you. The default is 33 minutes.
- Type: minutes
- Default value: 33 minutes
- -i | --jobid JOBID
- Optional
-
The job ID (requestId) of the deployment you want to cancel. If not specified, the default value is the ID of the most recent metadata deployment you ran using Salesforce CLI.
- Type: id
force:mdapi:deploy:report
Help for force:mdapi:deploy:report
Specify the job ID for the deploy you want to check. You can also specify a wait time (minutes) to check for updates to the deploy status.
Command Syntax
- sfdx force:mdapi:deploy:report
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- [-w WAIT]
- [-i JOBID]
- [--verbose]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -w | --wait WAIT
- Optional
-
The number of minutes to wait for the command to complete. The default is –1 (no limit). 0
- Type: minutes
- -i | --jobid JOBID
- Optional
-
The job ID (id field value for AsyncResult) of the deployment you want to check. The job ID is required if you haven’t previously deployed using Salesforce CLI. If you deploy using Salesforce CLI and don’t specify ajob ID, we use the ID of the most recent metadata deployment.
- Type: id
- --verbose
- Optional
-
Indicates that you want verbose output for deploy results.
- Type: boolean
force:mdapi:describemetadata
Help for force:mdapi:describemetadata
The default target username is the admin user for the default scratch org. The username must have the Modify All Data permission or the Modify Metadata permission (Beta). For more information about permissions, see Salesforce Help.
Examples:
1$ sfdx force:mdapi:describemetadata -a 43.01$ sfdx force:mdapi:describemetadata -u me@example.com1$ sfdx force:mdapi:describemetadata -f /path/to/outputfilename.txt1$ sfdx force:mdapi:describemetadata -u me@example.com -f /path/to/outputfilename.txtCommand Syntax
- sfdx force:mdapi:describemetadata
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [-a APIVERSION]
- [-f RESULTFILE]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- -a | --apiversion APIVERSION
- Optional
-
The API version to use. The default is the latest API version.
- Type: string
- -f | --resultfile RESULTFILE
- Optional
-
Filters all the known metadata from the result such that all that is left are the types not yet fully supported by the CLI.
- Type: filepath
force:mdapi:listmetadata
Help for force:mdapi:listmetadata
The default target username is the admin user for the default scratch org.
Examples:
1$ sfdx force:mdapi:listmetadata -m CustomObject1$ sfdx force:mdapi:listmetadata -m CustomObject -a 43.01$ sfdx force:mdapi:listmetadata -m CustomObject -u me@example.com1$ sfdx force:mdapi:listmetadata -m CustomObject -f /path/to/outputfilename.txt1$ sfdx force:mdapi:listmetadata -m Dashboard --folder foldername1$ sfdx force:mdapi:listmetadata -m Dashboard --folder foldername -a 43.01$ sfdx force:mdapi:listmetadata -m Dashboard --folder foldername -u me@example.com1$ sfdx force:mdapi:listmetadata -m Dashboard --folder foldername -f /path/to/outputfilename.txt1$ sfdx force:mdapi:listmetadata -m CustomObject -u me@example.com -f /path/to/outputfilename.txtCommand Syntax
- sfdx force:mdapi:listmetadata
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [-a APIVERSION]
- [-f RESULTFILE]
- -m METADATATYPE
- [--folder FOLDER]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- -a | --apiversion APIVERSION
- Optional
-
The API version to use. The default is the latest API version
- Type: string
- -f | --resultfile RESULTFILE
- Optional
-
The path to the file where the results of the command are stored. The default output destination is the console.
- Type: filepath
- -m | --metadatatype METADATATYPE
- Required
-
The metadata type to be retrieved, such as CustomObject or Report. The metadata type value is case-sensitive.
- Type: string
- --folder FOLDER
- Optional
-
The folder associated with the component. This parameter is required for components that use folders, such as Dashboard, Document, EmailTemplate, or Report. The folder name value is case-sensitive.
- Type: string
force:mdapi:retrieve
Help for force:mdapi:retrieve
The default target username is the admin user for the default scratch org. You can retrieve and deploy up to 10,000 files or 400 MB (39 MB compressed) at one time.
Command Syntax
- sfdx force:mdapi:retrieve
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [-a APIVERSION]
- [-w WAIT]
- -r RETRIEVETARGETDIR
- [-k UNPACKAGED]
- [--verbose]
- [-d SOURCEDIR]
- [-p PACKAGENAMES]
- [-s]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- -a | --apiversion APIVERSION
- Optional
-
Use to override the default, which is the latest version supported by your CLI plug-in, with the version in your package.xml file.
- Type: string
- -w | --wait WAIT
- Optional
-
The number of minutes to wait for the command to complete.
- Type: minutes
- -r | --retrievetargetdir RETRIEVETARGETDIR
- Required
-
The root of the directory structure where the retrieved .zip or metadata files are put.
- Type: directory
- -k | --unpackaged UNPACKAGED
- Optional
-
The complete path for the manifest file that specifies the components to retrieve.
- Type: filepath
- --verbose
- Optional
-
Indicates that you want verbose output from the retrieve operation.
- Type: boolean
- -d | --sourcedir SOURCEDIR
- Optional
-
The source directory to use instead of the default package directory specified in sfdx-project.json
- Type: directory
- -p | --packagenames PACKAGENAMES
- Optional
-
A comma-separated list of package names to retrieve.
- Type: array
- -s | --singlepackage
- Optional
-
Indicates that the specified .zip file points to a directory structure for a single package. By default, the CLI assumes the directory is structured for a set of packages.
- Type: boolean
force:mdapi:retrieve:report
Help for force:mdapi:retrieve:report
Specify the job ID and a target directory for the retrieve you want to check. You can also specify a wait time (minutes) to check for updates to the deploy status. If the retrieve was successful, the resulting zip file will be saved to the location passed in with the retrieve target parameter.
Command Syntax
- sfdx force:mdapi:retrieve:report
- [--json]
- [--loglevel LOGLEVEL]
- [-u TARGETUSERNAME]
- [--apiversion APIVERSION]
- [-w WAIT]
- [-r RETRIEVETARGETDIR]
- [--verbose]
- [-i JOBID]
Parameters
- --json
- Optional
-
Format output as JSON.
- Type: boolean
- --loglevel LOGLEVEL
- Optional
-
The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.
- Type: enum
- Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Default value: warn
- -u | --targetusername TARGETUSERNAME
- Optional
-
A username or alias for the target org. Overrides the default target org.
- Type: string
- --apiversion APIVERSION
- Optional
-
Override the API version used for API requests made by this command.
- Type: string
- -w | --wait WAIT
- Optional
-
The number of minutes to wait for the command to complete. -1
- Type: minutes
- -r | --retrievetargetdir RETRIEVETARGETDIR
- Optional
-
The root of the directory structure where the retrieved .zip or metadata files are put.
- Type: directory
- --verbose
- Optional
-
Indicates that you want verbose output from the retrieve operation.
- Type: boolean
- -i | --jobid JOBID
- Optional
-
The job ID (asyncId) of the retrieve you want to check. If not specified, the default value is the ID of the most recent metadata retrieval you ran using Salesforce CLI. You must specify a --retrievetargetdir. Use with --wait to resume waiting.
- Type: id