Newer Version Available

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

Step 3: Retrieve Components with Metadata API

With Salesforce CLI, retrieve a file representation of the specified components in your package.xml manifest.

Two Options for Metadata API Retrieve

You can use one of two commands to retrieve metadata components.

  1. To retrieve the components specified in your package.xml manifest, issue a retrieve call using a Salesforce CLI source command. On the command line, run this call with the appropriate file path:

    sfdx force:source:retrieve -x path/to/package.xml

    Metadata retrieve() is an asynchronous, file-based command. You can issue multiple retrieve or deploy requests that run on their own when resources are available.

    With this command, you send a request to retrieve all custom objects as specified in your package.xml manifest. Your requests are queued until our systems are ready to process your retrieve call. After your request is dequeued, your retrieve call is run. The client checks the status of the retrieve and notifies you when the call is complete. The call returns a file representation of the chosen components. When you use Salesforce CLI to issue a retrieve call, all these processes are automated.

    We use a source command rather than an mdapi command. Developers generally use source commands because they allow for source tracking. Source tracking includes information about which revision you’re working on and when the last changes were made, which makes source commands more developer-friendly. To run source commands, ensure that source tracking is enabled in your org.

  2. Alternatively, run this command in your terminal:

    sfdx force:mdapi:retrieve -k path/to/package.xml

    This mdapi command follows the same process as the source command. In practice, admins use mdapi commands more often because the commands don’t include source tracking.

Troubleshooting

If your retrieve call times out or an error occurs, run this command:

sfdx force:mdapi:retrieve -k path/to/package.xml

This command returns the status of your retrieve. If you encounter errors with your retrieve, this command returns error information for troubleshooting.