Newer Version Available
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()
Fields
| Field Name | Details |
|---|---|
| DurationSeconds |
|
| EndTime |
|
| PackagePushRequestId |
|
| StartTime |
|
| Status |
|
| SubscriberOrganizationKey |
|
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}