---
schema_version: "1"
id: de394b2f1c7de429f6befb00a68ae8eb53ca40c95a663944deb0e0fa428610fc
title: MetadataPackageVersion
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_tooling/tooling_api_objects_metadatapackageversion.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_metadatapackageversion.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 02429a9cabb68c28404e24553be06cfbf152d647c3bc0fe771948428346ce9d5
description: Represents a package version (managed or unmanaged) that has been uploaded from the org you’re logged in to. Available in Tooling API version 38.0 and later.
---
# MetadataPackageVersion

Represents a package version (managed or unmanaged) that has been uploaded from the org you’re logged in to. Available in Tooling API version 38.0 and later.

## Supported SOAP Calls

describeSObjects(), query(), retrieve()

## Supported REST HTTP Methods

GET

## Fields

| Field | Details |
| --- | --- |
| BuildNumber | 
Type

int

Properties

Filter, Group, Nillable, Sort

Description

The build number of the version. For example, if you upload two beta versions, they have build numbers 1 and 2. Then, when you upload a released build of the same version, the build number is 3. When you upload a new version, the build number resets to 1.



 |
| IsDeprecated | 

Type

boolean

Properties

Defaulted on create, Filter, Group, Sort

Description

Indicates whether the package version is deprecated. Available in API version 46.0 and later.



 |
| MajorVersion | 

Type

int

Properties

Filter, Group, Nillable, Sort

Description

The first number in a package version number. A version number either has an x.y format or an x.y.z format. The x represents the major version, y the minor version, and z the patch version.



 |
| MetadataPackageId | 

Type

reference

Properties

Filter, Group, Nillable, Sort

Description

The 18-character package ID, which starts with 033.



 |
| MinorVersion | 

Type

int

Properties

Filter, Group, Nillable, Sort

Description

The second number in a package version number. A version number either has an x.y format or an x.y.z format. The x represents the major version, y the minor version, and z the patch version.



 |
| Name | 

Type

string

Properties

Filter, Group, idLookup, Sort

Description

The name of the package version.



 |
| PatchVersion | 

Type

int

Properties

Filter, Group, Nillable, Sort

Description

The third number in a package version number, if present. A version number either has an x.y format or an x.y.z format. The x represents the major version, y the minor version, and z the patch version.



 |
| ReleaseState | 

Type

picklist

Properties

Filter, Group, Nillable, Restricted picklist, Sort

Description

If the package version is a beta version, the value is Beta. Otherwise, the value is Released.



 |

## Usage

Here are examples of the types of API queries you can perform.

| Query | String |
| --- | --- |
| Get all package versions for the package that has a MetadataPackageID of 033D00000001xQlIAI | SELECT Id, Name, ReleaseState, MajorVersion, MinorVersion, PatchVersion FROM MetadataPackageVersion WHERE MetadataPackageId = '033D00000001xQlIAI' |
| Get the package version for the package with a specific MetadataPackageID and a major version greater than 1 | SELECT Id FROM MetadataPackageVersion WHERE MetadataPackageId ='033D00000001xQlIAI' AND MajorVersion > 1 |
| Get released package versions for the package with a specific MetadataPackageID | SELECT Id FROM MetadataPackageVersion WHERE MetadataPackageId = '033D00000001xQlIAI' AND ReleaseState = 'Released' |

**Java Code Sample**

Suppose you want to push version 3.4.6 of your package to all orgs. Let’s write some code to identify the orgs eligible for the upgrade. This example demonstrates how to generate the list of subscriber orgs eligible to be upgraded to version 3.4.6 of a package.

This code sample uses the web Services Connector (WSC).

// Finds all Active subscriber orgs that have the package installed
String PACKAGE\_SUBSCRIBER\_ORG\_KEY\_QUERY = "Select OrgKey from PackageSubscribers where OrgStatus = 'Active' and InstalledStatus = 'I'";

// Finds all MetadataPackageVersions lower than the version given, including the list 
// of subscribers for each version
String METADATA\_PACKAGE\_VERSION\_QUERY = "Select Id, Name, ReleaseState, (%s) from"
	+ " MetadataPackageVersion where MetadataPackageId = '%s' AND ReleaseState = 'Released'"
	+ " AND (MajorVersion < 3 OR (MajorVersion = 3 and MinorVersion < 4)"
	+ " OR (MajorVersion = 3 and MinorVersion = 4 and PatchVersion < 6))";

// conn is an EnterpriseConnection instance initialized with a ConnectionConfig object
// representing a connection to the developer org of the package
QueryResult results = conn.query(String.format(METADATA\_PACKAGE\_VERSION\_QUERY, PACKAGE\_SUBSCRIBER\_ORG\_KEY\_QUERY));

// This list will hold all of the PackageSubscriber objects that are eligible for upgrade
// to the given version
List<PackageSubscriber> subscribers = new ArrayList<>();
for (SObject mpvso : results.getRecords()) {

		// Cast the sObject to a MetadataPackageVersion
		MetadataPackageVersion mpv = (MetadataPackageVersion) mpvso;

		// Add subscribers to our list
		if (mpv.getPackageSubscribers() != null) {
			for (SObject psso : mpv.getPackageSubscribers().getRecords()) {
				subscribers.add((PackageSubscriber) psso);
			}
	}
}

**Next Step**

Create a push request using PackagePushRequest.