0

Objective: After deployment is completed, use deployCallback to make a request to a rest API

I wrote the following code and put it in my SF instance

public class DeployStatus implements Metadata.DeployCallback {
    public void handleResult(Metadata.DeployResult result,
                             Metadata.DeployCallbackContext context) {
        if (result.status == Metadata.DeployStatus.Succeeded) {
            // Deployment was successful
            PostPipeline PostPipelineData = new PostPipeline();
            PostPipelineData.setDeployStatus('succeeded', result.Id);
            
        } else {
            // Deployment was not successful
            PostPipeline PostPipelineData = new PostPipeline();
            PostPipelineData.setDeployStatus('failed', result.Id);            
        }
    }
}

Unfortunately, this is not working. After a deployment in SF, regardless if it was successful or not, I did not receive any requests in my rest API also, I don't see any error message related to my apex class.

Could someone help and tell me what I am doing wrong? I am not an SF developer, I work with DevOps and I am just trying to solve a issue re to deploy package.xml

1 Answer 1

3

Metadata.DeployCallback is used with the Apex Metadata API. It has no effect if you perform a deployment from outside the Salesforce platform using a package.xml manifest.

There is no way to effect a callback upon a Metadata API deployment completing, in general.

5
  • Thanks for the answer. Is there any way to run custom code when the deployment completes, like an event or trigger? Sep 27, 2022 at 22:16
  • 2
    @JoaoVitorino if deploying with sfdx, just write a shell script for it.
    – sfdcfox
    Sep 27, 2022 at 22:51
  • 1
    Even if not using SFDX, any Metadata API tool should be able to poll for completion so that your automation "knows" when it's done.
    – David Reed
    Sep 27, 2022 at 23:16
  • That is the problem, I don´t want to check from time to time if the deploy finished, this is costing a lot of minutes of CICD. Using sfdx in a while loop is what I am doing right, instead, I created a listener that waits for a request when the deployment finishes. Right now I need to find a way, an event or trigger, to fire an apex code that will do the API request. Sep 28, 2022 at 7:17
  • You really cannot do that. You have to poll, one way or another.
    – David Reed
    Sep 28, 2022 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .