---
schema_version: "1"
id: de41ede0840cb9eb8857dfe8e58cf8902a449617a911d4578d31e4e8fddafad0
title: MetadataPackageVersion
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/object_reference/sforce_api_objects_metadatapackageversion.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_metadatapackageversion.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 11ed895d822f4b5a2e86268daaec2b2c16b2fa43ffb01d0cc9a640ed93a07ec9
description: Represents a package version (managed or unmanaged) that has been uploaded from the org you’re logged in to.
---
# MetadataPackageVersion

Represents a package version (managed or unmanaged) that has been uploaded from the org you’re logged in to.

## Supported Calls

describeSObjects(), query(), retrieve()

## Fields

| Field Name | 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 non-beta version, the build number is 3. When you upload a new version, the build number resets to 1.



 |
| IsDeprecated | 

Type

boolean

Properties

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 starting 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.