MetadataPackageVersion

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

Version 

Introduced in API version 37.0.

Supported SOAP API Calls 

describeSObjects(), query(), retrieve()

Supported REST API Methods 

GET, HEAD, Query

Fields 

BuildNumber 

  • Type: int

  • Required: No

  • 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

  • Required: No

  • Properties: Defaulted on create, Filter, Group, Sort

  • Introduced: API version 46.0

  • Description: Indicates whether the package version is deprecated.

  • Default value: false

MajorVersion 

  • Type: int

  • Required: No

  • 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

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

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

  • Relationship name: MetadataPackage

  • Relationship type: relationship

  • Refers to: MetadataPackage

MinorVersion 

  • Type: int

  • Required: No

  • 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

  • Required: No

  • Properties: Filter, Group, idLookup, Sort

  • Description: The name of the package version.

PatchVersion 

  • Type: int

  • Required: No

  • 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

  • Required: No

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

  • Possible values:

    • Beta — Beta

    • Released — Released

Usage 

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

QueryString
Get all package versions for the package that has a MetadataPackageID of 033D00000001xQlIAISELECT 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 1SELECT Id FROM MetadataPackageVersion WHERE MetadataPackageId ='033D00000001xQlIAI' AND MajorVersion > 1
Get released package versions for the package with a specific MetadataPackageIDSELECT 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).

1// Finds all Active subscriber orgs that have the package installed
2String PACKAGE_SUBSCRIBER_ORG_KEY_QUERY = "Select OrgKey from PackageSubscribers where OrgStatus = 'Active' and InstalledStatus = 'I'";
3
4// Finds all MetadataPackageVersions lower than the version given, including the list 
5// of subscribers for each version
6String METADATA_PACKAGE_VERSION_QUERY = "Select Id, Name, ReleaseState, (%s) from"
7	+ " MetadataPackageVersion where MetadataPackageId = '%s' AND ReleaseState = 'Released'"
8	+ " AND (MajorVersion < 3 OR (MajorVersion = 3 and MinorVersion < 4)"
9	+ " OR (MajorVersion = 3 and MinorVersion = 4 and PatchVersion < 6))";
10
11// conn is an EnterpriseConnection instance initialized with a ConnectionConfig object
12// representing a connection to the developer org of the package
13QueryResult results = conn.query(String.format(METADATA_PACKAGE_VERSION_QUERY, PACKAGE_SUBSCRIBER_ORG_KEY_QUERY));
14
15// This list will hold all of the PackageSubscriber objects that are eligible for upgrade
16// to the given version
17List<PackageSubscriber> subscribers = new ArrayList<>();
18for (SObject mpvso : results.getRecords()) {
19
20		// Cast the sObject to a MetadataPackageVersion
21		MetadataPackageVersion mpv = (MetadataPackageVersion) mpvso;
22
23		// Add subscribers to our list
24		if (mpv.getPackageSubscribers() != null) {
25			for (SObject psso : mpv.getPackageSubscribers().getRecords()) {
26				subscribers.add((PackageSubscriber) psso);
27			}
28	}
29}

Next Step

Create a push request using PackagePushRequest.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!