You must provide a callback class for the asynchronous deployment of custom metadata through Apex. This class must implement the Metadata.DeployCallback interface.
Salesforce calls your DeployCallback.handleResult() method asynchronously once the queued deployment completes. Because the callback is called as asynchronous Apex after deployment, there may be a brief period where the deploy has completed, but your callback has not been called yet.
The following are methods for DeployCallback.
public void handleResult(Metadata.DeployResult var1, Metadata.DeployCallbackContext var2)
Type: void
This is an example implementation of the Metadata.DeployCallback interface.
public class MyCallback implements Metadata.DeployCallback { public void handleResult(Metadata.DeployResult result, Metadata.DeployCallbackContext context) { if (result.status == Metadata.DeployStatus.Succeeded) { // Deployment was successful } else { // Deployment was not successful } } }
The following example uses this implementation for a deployment.
// Setup callback and deploy MyCallback callback = new MyCallback(); Metadata.Operations.enqueueDeployment(mdContainer, callback);