Skip to content

Instantly share code, notes, and snippets.

@soe
Last active December 19, 2015 16:49
Show Gist options
  • Save soe/5986740 to your computer and use it in GitHub Desktop.
Save soe/5986740 to your computer and use it in GitHub Desktop.
// this example request for metadata retrieve and then post to the heroku service
MetadataService.MetadataPort service = MetadataValidator.createService();
MetadataService.RetrieveRequest retrieveRequest = new MetadataService.RetrieveRequest();
retrieveRequest.apiVersion = 27;
retrieveRequest.packageNames = null;
retrieveRequest.singlePackage = true;
retrieveRequest.specificFiles = null;
retrieveRequest.unpackaged = new MetadataService.Package_x();
retrieveRequest.unpackaged.types = new List<MetadataService.PackageTypeMembers>();
MetadataService.PackageTypeMembers packageType = new MetadataService.PackageTypeMembers();
packageType.name = 'ApexClass';
packageType.members = new String[] { 'MetadataValidator' };
retrieveRequest.unpackaged.types.add(packageType);
MetadataService.AsyncResult aResult = service.retrieve(retrieveRequest);
MetadataService.AsyncResult[] aResults = service.checkStatus(new String[] { aResult.Id });
// only the first package
while(!aResults[0].done) {
aResults = service.checkStatus(new String[] { aResult.Id });
}
MetadataService.RetrieveResult retrieveResult = service.checkRetrieveStatus(aResults[0].Id);
// messages must be null for successful retrieve
if(retrieveResult.messages == null) {
// post the result
String resp = MetadataRetrieveHelper.retrievePost(aResult.Id, retrieveResult.zipFile);
// response is a list of file paths in the zip file, seperated by comma
System.debug('resp:'+ resp);
System.debug('process id:'+ aResult.Id);
}
// process is the asynresult id when the initial retreive request was made
// path is the path of the specific inside the zip file, if path is empty then all file paths are returned
MetadataRetrieveHelper.retrieveGet(process, '');
MetadataRetrieveHelper.retrieveGet(process, path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment