Skip to main content

How to replicate metadata download speeds using Salesforce CLI

How to use Salesforce CLI to benchmark metadata retrieval speeds and compare with Gearset

Written by Sam Wilson
Updated today

Is your metadata comparison in Gearset slow? Is it stuck downloading metadata for ages, even for a small number of items?

The most common reason is that the Salesforce Metadata API itself is slow to respond. To rule this out, you can use Salesforce CLI to download a specific subset of metadata and compare how long it takes.

You can also follow these steps using Workbench if you prefer a browser-based tool.

Why Salesforce CLI?

Salesforce CLI is Salesforce's official command-line tool. Like Gearset, it talks to Salesforce via the Metadata API. This makes it a good tool for benchmarking retrieval speeds against another tool that uses the same underlying API.

Note: Salesforce recommends using Salesforce CLI instead of Workbench. Workbench is an open-source community tool that Salesforce does not maintain.

Prerequisites

You'll need Salesforce CLI installed.

Check the CLI is available and up to date:

sf --version
sf update

You can run these commands from any terminal (Terminal on macOS, Command Prompt or PowerShell on Windows, or the integrated terminal in VS Code if you use it).

Step 1: Set up the CLI and authenticate

The CLI needs a Salesforce project to work from, even for simple operations. To create one:

sf project generate --name my-project
cd my-project

Then authenticate with the org you want to investigate:

sf org login web --alias my-org --set-default

This opens a browser window. Log in with the same credentials you use in Gearset. This is important for an accurate comparison.

Tip: If you hit login or redirect issues, specify the instance URL:

sf org login web \
--instance-url https://my-sandbox.my.salesforce.com \
--alias my-org \
--set-default

Step 2: Create a package.xml for the metadata you want to test

Pick a specific subset of metadata to test. Create a package.xml file in your project's manifest/ folder.

Example: retrieve a single Apex class:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>TestClass</members>
<name>ApexClass</name>
</types>
<version>66.0</version>
</Package>

Example: retrieve multiple standard objects:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Account</members>
<members>Case</members>
<members>Contact</members>
<members>Lead</members>
<members>Opportunity</members>
<members>Order</members>
<members>Task</members>
<members>User</members>
<name>CustomObject</name>
</types>
<version>66.0</version>
</Package>

For more on package.xml manifest files, see this Salesforce article.

Step 3: Retrieve the metadata and check the timing

  1. Run the retrieve command:

    sf project retrieve start --manifest manifest/package.xml

    The CLI prints a timing breakdown for each stage of the retrieval, including how long it spent waiting for the org to respond, and the total elapsed time. This is the number you want to compare against Gearset.

  2. Repeat the retrieval a few times to get an average, as individual calls can vary.

Step 4: Retrieve the same metadata using Gearset

Now retrieve the exact same metadata from the same org using Gearset, using the same package.xml file:

  1. On the Compare metadata page, select the same Salesforce org as both source and target.

  2. For the metadata filter, choose Upload a package.xml and upload the same package.xml file you used with the CLI. This makes sure you're comparing exactly the same metadata set.

  3. Click Compare now to start the retrieval. The CLI output showed you how long it spent waiting for the org to respond. In Gearset, you can see retrieval progress in the top left of the comparison screen. Time how long it takes until the progress indicator changes to a green tick.

  4. Repeat the comparison a few times to get an average, as individual retrievals can vary.

Comparing results

If the CLI retrieval times are similar to (or slower than) Gearset's, the slowness is likely coming from the Salesforce Metadata API rather than from Gearset.

If the CLI is noticeably faster, please let us know with the timing details so we can look into it.

Related articles

Did this answer your question?