Newer Version Available

This content describes an older version of this product. View Latest

PackagePushJob

Represents an individual push job for upgrading a package in an org from one version to another version. There can be multiple push jobs created for one push request. For example, if you want to upgrade five orgs as part of one push, you have one PackagePushRequest record and five PackagePushJob records.

Supported Calls

create(), describeSObjects(), query(), retrieve(), update(), upsert()

Special Access Rules

To initiate a push upgrade for a first-generation managed package, the Upload AppExchange Packages user permission is required.

To initiate a push upgrade for an unlocked or second-generation managed package, the Create and Update Second-Generation Packages user permission is required.

The push upgrade feature is only available to first- and second-generation managed packages that have passed AppExchange security review. To enable push upgrades for your managed package, log a support case in the Salesforce Partner Community.

For unlocked packages, push upgrades are enabled by default.

Fields

Field Name Details
DurationSeconds
Type
int
Properties
Group, Nillable
Description
The length of time in seconds, that the push upgrade took to complete. This field is new in API version 51.0.
EndTime
Type
dateTime
Properties
Create, Nillable, Update
Description
The date and time (UTC) at which the push upgrade ended, in ISO 8601 format. This field is new in API version 51.0.
PackagePushRequestId
Type
reference
Properties
Create, Filter, Group, Nillable, Sort, Update
Description
Required. The ID of the parent push request record that must have been created.
StartTime
Type
dateTime
Properties
Create, Nillable, Update
Description
The date and time (UTC) at which the push upgrade started, in ISO 8601 format. This field is new in API version 51.0.
Status
Type
picklist
Properties
Create, Filter, Group, Nillable, Restricted picklist, Sort
Description
The status of the job. Valid values are:
  • Canceled
  • Created (default)
  • Failed
  • In Progress
  • Pending
  • Succeeded
Don’t specify this value when you create the push job. The default value of Created is used.
SubscriberOrganizationKey
Type
string
Properties
Create, Filter, Group, Nillable, Sort, Update
Description
Required. The organization key of the org where the package is upgraded. This references orgKey in PackageSubscriber.

Usage

Suppose that you want to push version 3.4.6 of your package to all orgs. You’ve already identified the orgs eligible for the upgrade by using MetadataPackageVersion and created the push request using PackagePushRequest. Now let’s write some code to create a push job for each eligible org.

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

1PackageSubscriber[] subscribers = new PackageSubscriber[];
2
3// ... populate eligible and desired subscribers
4
5// Create the PackagePushJob array
6PackagePushJob[] jobs = new PackagePushJob[subscribers.length];
7
8for (int i = 0; i < subscribers.length; i++) {
9	// create a job for each subscriber...
10	PackagePushJob job = new PackagePushJob();
11	// ... associate it to the PackagePushRequest ppr...
12	job.setPackagePushRequestId(ppr.getId());
13	// ... and add the orgKey
14	job.setSubscriberOrganizationKey(subscribers[i].getOrgKey());
15	jobs[i] = job;
16}
17
18// Save the jobs
19SaveResult[] saveResults = conn.create(jobs);
20
21// Add the newly generated id's to the PackagePushJob objects
22for (int i = 0; i < saveResults.length; i++) {
23	if (saveResults[i].isSuccess()) {
24		jobs[i].setId(saveResults[i].getId());
25	}
26}
Or, if you’re using REST API, submit a POST request to the PackagePushJob sObject endpoint, as in the following example. SOAP API is also supported. This example returns the push job ID (starting with 0DX) that is required to query the status of the job.
1POST
2/services/data/v38.0/sobjects/packagepushjob/
3{
4   "PackagePushRequestId" : "0DV...",
5   "SubscriberOrganizationKey" : "00DR00..."
6}

Checking the Status of a Push Job

To check the job status, simply query the Status field. For example:
1SELECT Id, Status FROM PackagePushJob WHERE PackagePushRequestId ='0DV...'
Here’s an example in Java.
1// Finds the status of the PackagePushJob with the given id
2String PACKAGE_PUSH_JOB_STATUS_QUERY = "Select status from PackagePushJob where Id = '%s'";
3
4// job is a PackagePushJob instance
5QueryResult queryResult = conn.query(String.format(PACKAGE_PUSH_JOB_STATUS_QUERY, 
6job.getId()));
7
8// extract the status from the QueryResult 
9String status = ((PackagePushJob) queryResult.getRecords()[0]).getStatus();
10
11// optionally, update the PackagePushJob instance with the latest status
12job.setStatus(status);
You can also continuously poll the job status until the job is done. The following Java example polls the status every 10 seconds.
1// The set of states that indicate a PackagePushJob has completed
2final Set<String> TERMINAL_STATES = new HashSet<>();
3TERMINAL_STATES.add("Succeeded");
4TERMINAL_STATES.add("Failed");
5TERMINAL_STATES.add("Canceled");
6		
7String status = queryJobStatus(job); // this method returns the status as retrieved in the previous code sample
8
9// If the status is not one of the completed statuses...
10while(!TERMINAL_STATES.contains(status)) {
11	Thread.sleep(10 * 1000); // ... wait 10 seconds and try again
12	status = queryJobStatus(job);
13}