function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nikhil Garg 17Nikhil Garg 17 

Deploy Metadata using Deploy() method in apex

Hi Community,

I have been working on the functionality to deploy metadata to salesforce using deploy call.

This is my code:


MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        
        MetadataService.DeployOptions deployOptions = new MetadataService.DeployOptions();

        deployOptions.allowMissingFiles = false;
        deployOptions.autoUpdatePackage = false;
        deployOptions.checkOnly = false;
        deployOptions.ignoreWarnings = false;
        deployOptions.performRetrieve = false;
        deployOptions.purgeOnDelete = false;
        deployOptions.rollbackOnError = false;
        deployOptions.singlePackage = true;
        deployOptions.testLevel = 'NoTestRun';

 MetadataService.AsyncResult result = service.deploy(zipFileContent, deployOptions);

after getting response it gives me error 'No package.XML found' 

I have checked that My zip file contains package.xml for successfull deployment.  

But I'm encountering error for this.

Kindly suggest me any approach or any solution to troubleshoot this issue. I need to do it urgent.

Thanks
Nikhil GargScreenshot of zip fileUser-added image

 

 

VinayVinay (Salesforce Developers) 
Hi Nikhil,

You can check below examples to  Retrieve and Deploy Metadata through Apex.

https://sudipta-deb.in/2017/04/summer17-retrieve-and-deploy-metadata-through-apex.html
https://salesforce.stackexchange.com/questions/172155/deploying-metadata-through-metadata-operations-enqueuedeployment-fails-with-a-nu

Please mark as Best Answer if above information was helpful.

Thanks,
Nikhil Garg 17Nikhil Garg 17
Hi Vinay,

Thanks for your reply to my question, but the issue is related to deploy call of metadata or any other configuration.
if possible please provide any other solution to deploy the whole metadata and kindly give the structure of the package.xml file so that this can resolve.

Thanks