Retrieving Components from Your Managed Package Version in Salesforce
Question:
I have a developer org where I created a 1st-generation managed package with an assigned namespace. Over a year ago, I uploaded a released package version. Since then, I’ve implemented bug fixes, added features, and now plan to upload a new released package version. However, I need to create a release notes document, and I’ve lost track of all the changes made between the last released version and the current state of the package in the org. I am not using any source control system, such as Git, to track changes.
Is there a way to retrieve the components (Apex classes, flows, etc.) of that specific released package version, so I can compare them with the current components in the org? Note that I am the owner of the org, code, and package (not a subscriber).
Answer:

Yes, it is possible to retrieve the components of a specific released package version in your scenario. Since you own the org and the package, you can use the Salesforce CLI along with metadata retrieval techniques to fetch the contents of that specific package version. Here’s how you can do it:
Join our Salesforce Course for Beginners to master Admin, Developer, and AI modules with expert guidance, hands-on learning, and free demo classes!
Retrieve the Metadata of the Released Package Version Using the Metadata API
The Metadata API supports retrieving metadata for a specific package version. To fetch this, you need to construct a package manifest (package.xml
) that targets the desired package version.
Example package.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>Flow</name>
</types>
<!-- Include other metadata types as needed -->
<version>55.0</version>
</Package>
XML Declaration
<?xml version="1.0" encoding="UTF-8"?>
- Declares that this is an XML document.
- Specifies the version of the XML standard being used (
1.0
). - Indicates the character encoding format (
UTF-8
).
Root Element
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
- The
<Package>
element is the root element of the manifest file. - The
xmlns
attribute specifies the namespace for the Salesforce Metadata API schema (http://soap.sforce.com/2006/04/metadata
).
Metadata Types
ApexClass
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
: Represents a metadata type to include in the operation (e.g.,ApexClass
).<members>
: Specifies which components of the metadata type to include.- The wildcard (
*
) means all Apex classes in the org are included.
- The wildcard (
<name>
: Defines the type of metadata to retrieve (in this case,ApexClass
, which represents Apex classes).
Flow
<types>
<members>*</members>
<name>Flow</name>
</types>
- Similarly, this block retrieves all flows in the org:
<name>Flow</name>
indicates the metadata type for Flows (e.g., Screen Flows, Autolaunched Flows).<members>*</members>
retrieves all Flow components.
Version
<version>55.0</version>
- Specifies the Salesforce API version to use for the operation.
- API version
55.0
corresponds to a specific Salesforce release (e.g., Summer ’23). - Using the correct version ensures compatibility with the features and metadata supported in that release.
Purpose
This package.xml
file is typically used for the following:
- Retrieving Metadata: To fetch metadata components like Apex classes and Flows from a Salesforce org.
- Deploying Metadata: To upload specified components to another Salesforce org.
- Version Control: To export components for comparison, documentation, or backup.
How to Use It
- Save the XML code as a file named
package.xml
. - Use Salesforce CLI or another Metadata API-compatible tool to execute retrieval or deployment operations.
- Example CLI command for retrieval:
- Example CLI command for retrieval:
sfdx force:mdapi:retrieve -r ./outputDir -k ./package.xml -u YourOrgAlias
Extending the File
You can include additional metadata types as needed. For example, to include custom objects and their fields, you would add:
<types>
<members>*</members>
<name>CustomObject</name>
</types>
<types>
<members>*</members>
<name>CustomField</name>
</types>
Use Salesforce CLI to retrieve the components:
sfdx force:mdapi:retrieve -s -r ./outputDir -p "YourPackageName@X.X" -u YourOrgAlias
Explanation
The command sfdx force:mdapi:retrieve
is used to retrieve metadata from a Salesforce org using the Metadata API. The -s
flag specifies that the retrieval is for the source (rather than the target), and -r ./outputDir
sets the local directory where the metadata will be saved. The -p "YourPackageName@X.X"
indicates the package and version to retrieve, while -u YourOrgAlias
specifies the Salesforce org alias for the operation.
Example
Retrieve version 1.0
of the managed package MyPackage
from an org with alias DevOrg
and store it in the folder retrievedMetadata
:
sfdx force:mdapi:retrieve -s -r ./retrievedMetadata -p "MyPackage@1.0" -u DevOrg
Result
- A
.zip
file will be saved in the specified directory (./retrievedMetadata
) containing all the metadata components included in the managed package version1.0
. - You can extract the
.zip
file to view its contents, which will include components like Apex classes, Visualforce pages, custom objects, flows, and others specified in the package.
Use Case
This command is particularly useful for retrieving the state of a specific managed package version to:
- Compare it with another version or the current state of the org.
- Analyze changes for creating release notes or debugging.
- Use the metadata for deployment to other orgs.
Replace YourPackageName@X.X
with the specific package version name and number (e.g., MyPackage@1.2
).
2.Retrieve the Current State of Components in the Org
To compare the current components in the org, you can retrieve all metadata directly from the org using a similar approach. Update the package.xml
file to include all metadata types and run:
sfdx force:source:retrieve -x path/to/package.xml -u YourOrgAlias
3.Compare the Retrieved Metadata
Use a file comparison tool like Beyond Compare, WinMerge, or Git diff to compare the contents of the retrieved package version and the current org state. This will help you identify the changes made since the last released version.
4.Alternative: Use Package Components Report in Setup
Salesforce provides a “Package Components” view in Setup that lists all the components of a managed package version. Navigate to Setup > Installed Packages, locate your package, and view its details. While this doesn’t allow export, you can manually document or note the components for comparison.
5.Use Third-Party Tools
Consider tools like Gearset or Copado, which specialize in metadata comparison and can help you identify differences between the org and a specific package version more efficiently.
Summing Up
Retrieving components from a specific version of a managed package you own in Salesforce is essential for tasks like tracking changes, creating release notes, or ensuring version consistency. The process involves using the Salesforce Metadata API, typically via the Salesforce CLI, to extract metadata tied to a specific package version. By specifying the package name and version in the -p
flag of the sfdx force:mdapi:retrieve
command, you can precisely target the components associated with that version. This ensures that only managed components from your package are retrieved, avoiding unnecessary clutter from unmanaged components or other packages.
This approach is particularly useful if you lack a version control system like Git to track changes over time. The retrieved metadata can be stored locally, allowing for detailed comparisons between package versions or with the current state of your development org. By leveraging tools like diff
or specialized code comparison software, you can identify added, modified, or removed components, streamlining the process of documenting changes or preparing for your next package release. This ensures that you maintain a clear, auditable history of your managed package’s evolution, even if prior change tracking methods were not in place.
Salesforce Training in Chennai: Unlock Your Potential
Elevate your career with our comprehensive Salesforce training in Chennai, designed to equip you with expertise in Admin, Developer, and AI modules. Our program offers unparalleled certification guidance, rigorous interview preparation, and industry-aligned training to ensure you gain a competitive edge. With in-depth modules and expert-led sessions, you’ll build a solid foundation in Salesforce while mastering advanced techniques to meet real-world demands.
Our unique learning approach combines practical hands-on sessions with detailed class notes, enabling you to gain job-ready skills and confidence. Whether you’re starting fresh or upskilling, our training ensures you stand out in the fast-paced Salesforce ecosystem.
Take the first step toward your success by joining our free demo class today and experience the best in Salesforce education!!!