// (example from Daniel Ballinger) public void checkDeployStatus(Id deployRequestId) { HttpRequest req = new HttpRequest(); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); req.setHeader('Content-Type', 'application/json'); req.setMethod('GET'); String instanceName = System.Url.getSalesforceBaseUrl().toExternalForm(); // Visualforce can't make the direct API calls. Might need to massage the instanceName req.setEndpoint(instanceName + '/services/data/v49.0/metadata/deployRequest/' + deployRequestId + '?includeDetails=true'); Http http = new Http(); try { HTTPResponse res = http.send(req); System.debug('STATUS:' + res.getStatus()); System.debug('STATUS_CODE:' + res.getStatusCode()); String responseBody = res.getBody(); if(res.getStatusCode() == 200) { DeployResultJson jsonResult = (DeployResultJson)JSON.deserialize(responseBody, DeployResultJson.class); if(jsonResult.deployResult.details != null) { for(Metadata.DeployMessage dm : jsonResult.deployResult.details.componentSuccesses) { if(dm.fileName == 'package.xml') { continue; } // Do something with the DeployMessage } } } } catch(System.CalloutException e) { // Exception handling goes here } } // Support unpacking via JSON.deserialize from deployRequest metadata api call public class DeployResultJson { public String id; public Object validatedDeployRequestId; public Object deployOptions; public Metadata.DeployResult deployResult; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter