Create Downloadable Salesforce Packages with VS Code & CLI : Shubham

Create Downloadable Salesforce Packages with VS Code & CLI
by: Shubham
blow post content copied from  SalesForce FAQs
click here to view original post



### Summary of Creating Downloadable Salesforce Packages with VS Code & CLI To create a package in Salesforce, you can use the package manager, which allows you to add components and generate an installation URL. However, if the package is deleted from the source organization, users from other organizations won't be able to install it. To prevent this, you can download the package as a zip file, allowing others to install it even if it has been deleted from the source org. This guide explains how to create downloadable Salesforce packages using Visual Studio Code (VS Code) and Salesforce Command Line Interface (CLI). Here’s a simplified breakdown of the process: 1. **Set Up Your Environment**: Ensure you have VS Code and Salesforce CLI installed. 2. **Create a Salesforce Project**: - Open the Command Palette in VS Code (Ctrl+Shift+P). - Select "SFDX: Create Project With Manifest" and follow the prompts to name and save your project. 3. **Connect VS Code to Salesforce Org**: - In the Command Palette, select "SFDX: Authorize an Org" and log in to your Salesforce org. 4. **Retrieve Components**: - Open the `package.xml` file and use the command "SFDX: Retrieve Source in Manifest from Org" to fetch components like Apex classes and Visualforce pages. 5. **Edit package.xml**: - Add the components you want to include in the package. For instance, if you have a flow that depends on a custom object, ensure to include all related components in the `package.xml`. 6. **Create the Zip File**: - Use the command `sfdx force:mdapi:retrieve -r ./mdapi_output -k ./manifest/package.xml -u SourceOrg --wait 10` to create a zip file containing your package. 7. **Deploy the Package**: - To deploy the package to another org, log into that org via VS Code, add the zip file to your project, and use the command `sfdx force:mdapi:deploy -u TargetOrg -f ./mdapi_output/unpackaged.zip -w -1`. ### Conclusion This process allows you to create and deploy Salesforce packages efficiently, even if the original package is deleted from the source organization. By following these steps, you can ensure that your components are easily shareable and deployable across different Salesforce environments. ### Additional Context - **Unmanaged vs. Managed Packages**: Unmanaged packages are typically used for open-source projects or when you want to share code without restrictions, while managed packages are used for distributing applications with version control and upgrade capabilities. - **Salesforce CLI**: This is a powerful tool that allows developers to interact with Salesforce orgs from the command line, making it easier to automate tasks and manage deployments. ### Hashtags for SEO #Salesforce #VSCode #SalesforceCLI #PackageManagement #UnmanagedPackages #SalesforceDevelopment #MetadataDeployment #SalesforceTutorial #CloudComputing #SoftwareDevelopment


To create a package in Salesforce, we use the package manager that adds components and generates an installation URL after uploading the package. This is a very easy way to create and deploy a package in Salesforce, allowing others to install it directly.

The issue arises when the created package is deleted from the source org. As a result, a user from another org attempting to install the package will be unable to access it, as it has been deleted from the source org.

To use the package in the target org, even if it is deleted from the source org, we need to download it in a zip file. Then, even if the source org deletes the data, other users can still install the package using the downloaded zip file.

In this article, we will explain how to create downloadable Salesforce packages with VS Code & CLI.

Create Package Using VS Code + Salesforce CLI

There are two ways to retrieve components from the Salesforce org to create the package, which we can deploy in the target org, even if those components are deleted from the source org

  1. Workbench: We can create and deploy a package using the Workbench in Salesforce.
  2. VS Code + Salesforce CLI: To use VS Code, the Salesforce CLI must be installed in VS Code.

Before creating the package, you must have installed VS Code and the Salesforce CLI.

Next, I’ll walk you through creating a project, generating a package.xml file, and converting it to a zip file using VS Code and Salesforce CLI. Follow the steps below.

1. Create a Salesforce Project and Folder

To create a project from a command, click the View menu and then select the Command Palette option.

Alternatively, you can press Ctrl+Shift+P to open the command bar. In the command, you need to search for and select SFDX: Create Project With Manifest.

Then, you need to select the Project Template. Here, I selected the Standard Template and pressed the Enter key.

Create Project in Salesforce

After selecting the template, you have to enter the Project Name and press the Enter key.

Setup VS Code for Salesforce Org

Now, we need to select a Folder so that we can save our project. To do that, select an existing folder or create a new folder and click the Create Project button.

How to Setup VS Code for Salesforce Org

2. Connect VS Code to Salesforce Org

Now, we need to connect VS Code to the Salesforce Org. For that, again, open the Command Palette. In the command, you need to search for and select SFDX: Authorize an Org.

Then, you need to select the default org that you are using. Here, I’m using Production org. If you have logged in through the URL to your org, then you can select Project Default or the Production org option.

Setup Vs Code and Connect to Salesforce Org

After that, you will be redirected to the Salesforce Org login screen. Here, you need to enter credentials, or you will get a confirmation screen asking if you want to allow the Salesforce Org to connect to VS Code. There, you need to click the Allow button.

How to Setup Vs Code and Connect to Salesforce Org

After that, you will be connected to the Salesforce Org using VS Code and receive an Authentication Successful message.

Connect VS Code to Salesforce Org

3. Retrieve Component from Salesforce Org to the VS Code

Now, we need to fetch the apex classes and VF pages created in the Salesforce Developer Console. Navigate to the Package.xml file and open it in the code editor.

Then, right-click on the opened code. A pop-up window will open, and in that window, select SFDX: Retrieve Source in Manifest from Org.

How to Connect VS Code to Salesforce

After that, you will see all the apex classes and VF pages that you have already created in the Salesforce org and will be connected to them.

Retrieve Data From Salesforce Org

4. Add Component to Package.xml File

To retrieve the component from the Salesforce org, we need to add the component to the package.xml file, which is located under the manifest option.

You can create a different XML file or edit the existing package.xml file as I showed below. Add the components that you want to retrieve from the Salesforce org.

For example, I want to create a package for the flow that I created to add CC recipients dynamically in Salesforce flow.

This flow is dependent on the custom object named CC Recipients__c. In this object, I stored the email addresses in the email fields.

If the Flow references Custom Objects, Email Templates, or Custom Fields, they must also be included in package.xml; otherwise, deployment may fail.

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

<types>
    <members>Add_CC_List</members>
    <name>Flow</name>
</types>

<types>
    <members>CC_Email_List__c</members>
    <members>Apply_Leave__c</members>
    <name>CustomObject</name>
</types>

    <version>64.0</version>
</Package>

You can see we have added a component to the package.xml file. Then, to create the zip file, you need to run the following command:

sfdx force:mdapi:retrieve -r ./mdapi_output -k ./manifest/package.xml -u SourceOrg --wait 10

Using this command, you can retrieve the metadata (component), create a zip file named unmanged.zip (by default), and create a folder named mdapi_output to store the zip file.

In the image, you can see the folder path where we stored the zip file.

Create Package Using VS Code and Salesforce CLI

In the image below, you can also see that the zip file has been created in our system. You can share this file with other users who have a Salesforce org account.

Unmanaged Package Zip File in Salesforce

In this way, we can create the downloadable package.xml zip file, which contains the component that you wanted to deploy on the different Salesforce orgs.

Deploy Package to Different Salesforce Org Using VS Code + CLI

Now we will deploy this package to other Salesforce orgs. Before deploying to another org, let me show you the components we added in the above package that are not available in this org.

Below, you can see there are no components available in this org. Now we will install the package that we created.

Salesforce Object Manager

Next, open VS Code and log in to connect with the new Salesforce org where we will deploy the package.

Next, add the unpackaged.zip file to the project folder you created, as shown below.

You can see I added the package file to the project by creating a new folder named mdapi_output. This folder will display in VS Code under the project.

Deploy Unmanaged Package uing VS Code and Salesforce CLI

On the left side, you’ll find the project folder, which contains the mdapi_output folder with the zip file.

Next, you can log in using the command or from the Command Palette. In the command, you need to search for and select SFDX: Authorize an Org. to connect VS Code to the Salesforce org, as given below:

sfdx auth:web:login -a TargetOrg

Here, the TargetOrg is our alias to verify the org where we are going to deploy the package.

After that, we need to provide a command to deploy the package as given below:

sfdx force:mdapi:deploy -u TargetOrg -f ./mdapi_output/unpackaged.zip -w -1

Using this command, the package will get deployed in this org. After that, you can see the Deploy ID and the Components that have been deployed.

Create Downloadable Salesforce Packages with VS Code & CLI

To check the installed components, open your target (in which org you deployed the package). As you can see, earlier we couldn’t find the components, but after deploying the package, we can see the components (metadata) that we retrieved from the source org.

Deployed Unmanaged Package in Salesforce

In this way, we can deploy the unmanaged package by installing a ZIP file in Salesforce.

Conclusion

I hope you have got an idea about how to create downloadable Salesforce packages with VS Code & CLI. 

In this, I have explained how to create a package.xml file in which we can add the components that we want to deploy in different orgs. We then learned how to deploy a package downloaded as a ZIP file using VS Code and Salesforce CLI.

You may like to read:

The post Create Downloadable Salesforce Packages with VS Code & CLI appeared first on SalesForce FAQs.


August 20, 2025 at 09:49PM
Click here for more details...

=============================
The original post is available in SalesForce FAQs by Shubham
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce