Newer Version Available

This content describes an older version of this product. View Latest

Deploy Changes to a Sandbox for Validation

When you’re ready to validate your source, convert your Salesforce DX source to Metadata API source format. You can then deploy to a sandbox.

You can deploy or retrieve up to 10,000 files at once. The maximum size of the deployed or retrieved .zip file is 400 MB (39 MB compressed). If either limit is exceeded, the operation fails.

You can increase the efficiency of your sandbox and production deployments by using tests you’ve already done in the scratch org. Run only the tests that are required, such as tests for Apex classes and triggers that change for the deployment. To run only specified tests when you deploy, set -l to RunSpecifiedTests and use -r to specify a comma-separated list of tests for deployment-specific changes to your Apex code.

1sfdx force:mdapi:deploy -d mdapi_output_dir/ -u "sandbox_username" -l RunSpecifiedTests -r test1,test2,test3,test4

Note

The username can be the org username or an alias.
  1. To ensure that your project is up to date, synchronize the source in your local file system with your development scratch org.
    1sfdx force:source:pull
  2. From the project, create directory for your source and convert the source to Metadata API format.
    1. Create a directory for the converted source.
      1mkdir mdapi_output_dir
    2. Convert the source to Metadata API format, and put the converted source in the output directory that you created.
      1sfdx force:source:convert -d mdapi_output_dir/ --packagename package_name

      The source:convert command creates the package manifest file, package.xml. The package.xml manifest file lists the metadata to retrieve or deploy. Creating a package.xml file that you can modify gives you flexibility and control over the components that you’re retrieving or deploying.

      Note

    3. List the contents of the output directory to confirm that it’s what you expected.
      1ls -lR mdapi_output_dir/
  3. Deploy the metadata from the directory to the sandbox, specifying deployment-specific tests as needed.
    1sfdx force:mdapi:deploy -d mdapioutput_dir/ -u "sandbox_username" -l RunSpecifiedTests -r test1,test2,test3,test4
    Messages similar to the following display.
    1=== Status 
    2Status: Pending 
    3jobid: 0AfB0000009SvyoKAC 
    4Component errors: 0 
    5Components deployed: 0 
    6Components total: 0 
    7Tests errors: 0 
    8Tests completed: 0 
    9Tests total: 0

    If the deployment job wait time is 1 minute or more, the status messages update every 30 seconds.

  4. If your deployment exceeds the wait time before it completes, use force:mdapi:deploy:report to check the deployment status. The default wait time is 0 minutes. Use the --wait parameter to specify a longer wait time.
    For example, to check a deployment job and add 5 more minutes to the wait time:
    1sfdx force:mdapi:deploy:report -w 5
    The sandbox username can be the org username or an alias.