Newer Version Available

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

cancelDeploy()

Cancels a deployment that hasn’t completed yet.

Syntax

1CancelDeployResult = metadatabinding.cancelDeploy(string id)

Usage

Use the cancelDeploy() operation to cancel a deployment in your organization started by the deploy() operation, which includes deployments started by the Force.com Migration Tool and the Force.com IDE. The deployment can be in a queue waiting to get started, or can be in progress. This operation takes the ID of the deployment you wish to cancel and returns a CancelDeployResult object. When the deployment is in the queue and hasn’t started yet, calling cancelDeploy() cancels the deployment immediately. When the deployment has started and is in progress, it might not get canceled immediately, so you should call checkDeployStatus() to check the status of the cancellation.

Cancel a deployment using these steps.

  1. Obtain the ID of the deployment you wish to cancel. For example, you can obtain the ID from the deploy() call in the AsyncResult object id field. Alternatively, you can obtain the ID in the Salesforce user interface from Setup by clicking Deployment Status or Deploy | Deployment Status, and by noting the ID of a deployment started by the API.
  2. Issue a cancelDeploy() call to start the cancellation process. This call returns a CancelDeployResult object.
  3. Check the value in the done field of the returned CancelDeployResult. If the done field value is true, the deployment has been canceled and you’re done. If the done field value is false, the cancellation is in progress, and follow these steps to check the cancellation status.
    1. Call checkDeployStatus() using the deployment ID you obtained earlier.
    2. In the returned DeployResult object, check the status field. If the status is Canceling, this means the cancellation is still in progress, and repeat steps a and b. Otherwise, if the status is Canceled, this means the deployment has been canceled and you’re done.

The deploy() operation throws these API faults.

INVALID_ID_FIELD with the message Invalid deploy ID
The specified ID argument doesn’t correspond to a valid deployment.
INVALID_ID_FIELD with the message Deployment already completed
The specified deployment has already completed.

Version

Available in API version 30.0 and later.

Permissions

Your client application must be logged in with the “Modify All Data” permission.

Arguments

Name Type Description
id string The ID of the deployment to cancel.

Sample Code—Java

This sample shows how to cancel a deployment. The sample calls cancelDeploy() by passing it a given deployment ID. Next, it checks whether the cancellation has completed, and if not, calls checkDeployStatus in a loop.

1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void cancelDeploy(String asyncId) throws Exception {
18    // Issue the deployment cancellation request  
19    CancelDeployResult result = metadataConnection.cancelDeploy(asyncId);
20    
21    // If the deployment cancellation completed, write a message to the output.
22    if (result.isDone()) {
23        System.out.println("Your deployment was canceled successfully!");
24    }
25    else {
26        // The deployment cancellation is still in progress, so get a new status 
27        DeployResult deployResult = metadataConnection.checkDeployStatus(asyncId, false);
28    
29        // Check whether the deployment is done. If not done, this means 
30        // that the cancellation is still in progress and the status is Canceling.        
31        while (!deployResult.isDone()) {
32            // Assert that the deployment status is Canceling
33            assert deployResult.getStatus() == DeployStatus.Canceling;
34            // Wait 2 seconds
35            Thread.sleep(2000);
36            // Get the deployment status again
37            deployResult = metadataConnection.checkDeployStatus(asyncId, false);
38        }
39        
40        // The deployment is done. Write the status to the output.
41        // (When the deployment is done, the cancellation should have completed
42        // and the status should be Canceled. However, in very rare cases,  
43        // the deployment can complete before it is canceled.) 
44        System.out.println("Final deploy status = >" + deployResult.getStatus());
45    }
46}