Newer Version Available
Deploy Metadata with Apex Testing Using REST
You can deploy or retrieve up to 10,000 files at once. AppExchange packages use different limits: They can contain up to 35,000 files. The maximum size of the deployed or retrieved .zip file is 39 MB. If the files are uncompressed in an unzipped folder, the size limit is 400 MB.
- URI
- https://host/services/data/vXX.0/metadata/deployRequest
- Formats
- JSON
- HTTP Method
- POST
- Authentication
- Authorization: Bearer token
deployOptions Parameters
| Parameter | Description |
|---|---|
| allowMissingFiles | Boolean. If files that are specified in package.xml are not in the .zip file, specifies whether a deployment can still succeed. Do not set this argument for deployment to production orgs. |
| autoUpdatePackage | Reserved for future use. |
| checkOnly | Boolean. Defaults to false. Set to true to perform a test deployment (validation) of components without saving the components in the target org. A validation enables you to verify the results of tests that would be generated in a deployment, but doesn’t commit any changes. After a validation finishes with passing tests, it might qualify for deployment without rerunning tests. See Deploy a Recently Validated Component Set Without Tests. |
| ignoreWarnings | Boolean. Indicates whether a deployment is
allowed to complete successfully despite one or more warnings (true) or not (false). Defaults to false. The DeployMessage object for a warning contains the following values:
If a warning occurs and ignoreWarnings is set to true, the success field in DeployMessage is true. If ignoreWarnings is set to false, success is set to false and the warning is treated like an error. |
| performRetrieve | Reserved for future use. |
| purgeOnDelete | Boolean. If true, the deleted components in the
destructiveChanges.xml manifest file aren't stored in the
Recycle Bin. Instead, they become immediately eligible for deletion. This option only works in Developer Edition or sandbox orgs. It doesn't work in production orgs. |
| rollbackOnError | Boolean. Indicates whether any failure causes a complete rollback (true) or not (false). If false, whatever actions can be performed without errors are performed, and errors are returned for the remaining actions. This parameter must be set to true if you are deploying to a production org. The default is false. |
| runTests | String[]. A list of Apex tests to run during deployment. Specify the class
name, one name per instance. The class name can also specify a namespace with a dot
notation. For more information, see Running a Subset of Tests in a Deployment. To use this option, set testLevel to RunSpecifiedTests. |
| singlePackage | Boolean. Indicates whether the specified .zip file points to a directory structure with a single package (true) or a set of packages (false). |
| testLevel | TestLevel (enumeration of type string). Optional. Specifies which tests are run as part of a deployment.
The test level is enforced regardless of the types of components that are present in the
deployment package. Valid values are:
If you don’t specify a test level, the default test execution behavior is used. See Running Tests in a Deployment. |
Request Body: Deploy Metadata
When you deploy metadata, your request includes both the deployment parameters and the .zip file containing the component directories and the manifest. Set the header to Content-Type: multipart/form-data,
- The POST request header is set to Content-Type: multipart/form-data and defines a boundary value to encapsulate different subparts of the request.
- In the subpart after the first boundary, a JSON request creates a deployOptions child object for passing the deployment parameters.
- The subpart after the second boundary specifies the .zip file containing the manifest and the component directories.
1POST /services/data/v48.0/metadata/deployRequest
2Authorization: Bearer 00D....
3Content-Type: multipart/form-data; boundary=--------------------------BOUNDARY
4----------------------------BOUNDARY
5Content-Disposition: form-data; name="json"
6Content-Type: application/json
7{
8 "deployOptions" :
9 {
10 "allowMissingFiles" : false,
11 "autoUpdatePackage" : false,
12 "checkOnly" : false,
13 "ignoreWarnings" : false,
14 "performRetrieve" : false,
15 "purgeOnDelete" : false,
16 "rollbackOnError" : false,
17 "runTests" : null,
18 "singlePackage" : true,
19 "testLevel" : "RunAllTestsInOrg"
20 }
21 }
22----------------------------BOUNDARY
23Content-Disposition: form-data; name="file"; filename="deploy.zip"
24Content-Type: application/zip
25
26//Contents of deploy.zip
27----------------------------BOUNDARY--Response Body: Deploy Metadata
When an HTTP status code of 201 (Created) is returned, your request has succeeded and resulted in the creation of a deployment that is being processed.
1{ "id" : "0Afxx00000001VPCAY",
2 "deployOptions" :
3 { "checkOnly" : false,
4 "singlePackage" : false,
5 "allowMissingFiles" : false,
6 "performRetrieve" : false,
7 "autoUpdatePackage" : false,
8 "rollbackOnError" : true,
9 "ignoreWarnings" : false,
10 "purgeOnDelete" : false,
11 "runAllTests" : false },
12 "deployResult" :
13 { "id" : "0Afxx00000001VPCAY",
14 "success" : false,
15 "checkOnly" : false,
16 "ignoreWarnings" : false,
17 "rollbackOnError" : true,
18 "status" : "Pending",
19 "runTestsEnabled" : false,
20 "done" : false } }deployResult Parameters
| Parameter | Description | |
|---|---|---|
| id | ID. ID of the component being deployed. | |
| canceledBy | ID. The ID of the user who canceled the deployment. | |
| canceledByName | String. The full name of the user who canceled the deployment. | |
| checkOnly | Boolean. Indicates whether this deployment is being used to check the validity of the deployed files without making any changes in the org (true) or not (false). A check-only deployment doesn’t deploy any components or change the organization in any way. | |
| completedDate | DateTime. Timestamp for when the deployment process ended. | |
| createdBy | ID. The ID of the user who created the deployment. | |
| createdByName | String. The full name of the user who created the deployment. | |
| createdDate | DateTime. Timestamp for when the deploy request was received. | |
| details | DeployDetails. Provides the details of a deployment that is in-progress or ended if ?includeDetails=true is added as a query to the GET request. | |
| done | Boolean. Indicates whether the server finished processing the deploy request for the specified id. | |
| errorMessage | String. Message corresponding to the values in the errorStatusCode field, if any. | |
| errorStatusCode | String. If an error occurred during the deploy request, a status code is returned, and the message corresponding to the status code is returned in errorMessagefield. | |
| ignoreWarnings | Boolean. Optional. Defaults to false. Specifies whether a deployment continues even if the deployment generates warnings. Do not set this argument to true for deployments to production organizations. | |
| lastModifiedDate | DateTime. Timestamp of the last update for the deployment process. | |
| numberComponentErrors | Int. The number of components deployed in the deployment process. Use this value with the numberComponentsTotal value to get an estimate of the deployment’s progress. | |
| numberComponentsTotal | Int. The total number of components in the deployment. Use this value with the numberComponentsDeployed value to get an estimate of the deployment’s progress. | |
| numberTestErrors | Int. The number of Apex tests that have generated errors during this deployment. | |
| numberTestsCompleted | The number of completed Apex tests for this deployment. Use this value with the numberTestsTotal value to get an estimate of the deployment’s test progress. | |
| numberTestsTotal | Int. The total number of Apex tests for this deployment. Use this value with the numberTestsCompleted value to get an estimate of the deployment’s test progress. The value in this field is not accurate until the deployment has started running tests for the components being deployed. | |
| runTestsEnabled | Boolean. Indicates whether Apex tests were run as part of this deployment (true) or not (false). Tests are either automatically run as part of a deployment or can be set to run in the deployOptions child object. | |
| rollbackOnError | Boolean. Defaults to true. Indicates whether any failure causes a complete rollback (true) or not (false). If false, whatever set of actions can be performed without errors are performed, and errors are returned for the remaining actions. This parameter must be set to true if you are deploying to a production org. | |
| startDate | DateTime. Timestamp for when the deployment process began. | |
| stateDetail | String. Indicates which component is being deployed or which Apex test class is running. | |
| status | Indicates the current state of the deployment. The valid values are:
|
|
| success | Boolean. Indicates whether the deployment was successful (true) or not (false). |