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 |
|
| IsDeprecated |
|
| MajorVersion |
|
| MetadataPackageId |
|
| MinorVersion |
|
| Name |
|
| PatchVersion |
|
| ReleaseState |
|
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.