Limit on Enqueued Deployments from Apex

We limit the number of Metadata API deployments originating from Apex that can be enqueued at a time. This limit helps preserve service function and resources for all customers on a server. Because this limit is a queue-depth limit, as long as the server can keep dequeuing, you can keep enqueuing deploys through Apex. This limit is based on analysis to make sure that it doesn’t affect your day-to-day operations.

When you reach the limit, you receive this exception as an API response in Apex.

[
{
  "message" : "The service received too many metadata deployment requests from Apex and doesn’t have the resources to accept new requests",
  "errorCode" : "System.AsyncException"
}
]

The limit applies only to enqueued Metadata API deployments that originate from Apex. It doesn’t affect Metadata API deployments from Salesforce CLI, change sets, or packaging. The limit does apply if a package contains Apex that triggers metadata deployments. It also applies to the Metadata.Operations.enqueueDeployment() Apex method. This limit applies to all Salesforce editions.