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
sara .netsara .net 

Use of Metadata API

Hi,

 I am using the declarative approach for creating the custom Objects in force.com through Metadata API's. Am facing an unique problem, In declarative approach entire object details will be in an XML file and we need to create a "Zip" package and pass this Zip Package file as input to "Deploy()" method. creation of Zip file can be done in 2 ways,

1. by using the "WinZip" tool.

2. Programmatically by using "Java.util.Zip" package.

If the zip file is created manually using the WinZip tool and if that file is passed as input parm to "Deploy()" method then object creation is successful. if we pass in the Zip file that is created programmatically to "Deploy()" method, method returns true which indicates that operation is successful, but custom objects are not getting created on the force.com.

There is no way to check if the web service method "Deploy()" has successfully processed the request or not. Any thoughts/solutions for this problem.

 

Regards

Sara

SuperfellSuperfell
You use the checkDeployStatus call to determine the status of the deploy call.
http://www.salesforce.com/us/developer/docs/api_meta/index_CSH.htm#meta_checkdeploystatus.htm
sara .netsara .net

We are using CheckDeploystatus() and CheckStatus() to check the deployment status, CheckDeployStatus() as well as CheckStatus() returns true, but when we verify the same on the force.com site, custom objects were not created. Even we tried printing the Error message, but no errors were returned as part of Deploy() web service call.

Same code works fine if the Zip file is created through winZip utilityand objects are getting created.

I have attached the code for refrence.

arrAsyncRes[0] = binding.deploy(byte1, depOptions);

for(int i= 0;i<arrAsyncRes.length;i++)

            {

                     ID = arrAsyncRes[i].getId();

                     ID1 = new String[1];

                     ID1[0] = ID;

                     arrAsyncRes_ChkStatus = binding.checkStatus(ID1);

                     DeployResult dplyresult = binding.checkDeployStatus(ID1[i]);

                     System.out.println("success    "+dplyresult.isSuccess());

                     DeployMessage[] DM =dpr.getMessages();

                    

                    System.out.println(DM[i].getProblem());

                    

                     System.out.println("Isdone "+ arrAsyncRes_ChkStatus.isDone());

            }

 

raorao

Hi Sara,

arrAsyncRes[0] = binding.deploy(byte1, depOptions);

 
Can u please tell how u constructed the 'binding' object. where u r giving salesforce source and destination login credentials for web service(metadata API) object.  If u can give the entire code that we will be very helpful to me.  We are facing huge problem in migrating code from development to production.
 
U r help is appreciated.
 
 
thanks
 
Rao
SuperfellSuperfell
you need a sessionId, you can get one via a web-tab style integration, or by calling login from the enterprise or partner APIs.
MiddhaMiddha

Hi All,

 

I am facing exactly the same issue. The zip file gets deployed if zipped using winzip but not from java.zip.util. Is there any solution to this?

 

I am using partner wsdl to login, and the checkstatus shows that the file is successfuly deployed but nothing happens in salesforce.

 

Please help,

/G

SuperfellSuperfell
Have you tried opening you zip file that doesn't work with winzip and comparing the 2 ?
MiddhaMiddha

Hi Simon,

 

Yes i did tried comparing the 2 and both looks identitical. Might be some difference between the compression method and level which i am not able to figure out.

 

Even if i create a zip file using java.util.zip then unzip  and zip the same file using winzip/7zip and deployed to salesforce and it works. This shows that winzip is adding something to the zip file which makes it work.

 

I have been spending 2 days around this with all sorts of experiments i could do, hope you can help me on this.

 

/G

SCYForce1SCYForce1

Any updates on this? I am facing the same issue, I dont know why the status is completed, but the zip file never got deploy to the org.

SomeshSomesh

The Force.com IDE and the Force.com Migration Tool both zip files in Java and work fine.

I am wondering if you're doing something wrong with the relative paths while creating ZipEntries that get added to the zip in Java.

 

how did you compare the 2 zips?

SomeshSomesh

also, are you setting the time and size for the ZipEntry in your Java program?

SCYForce1SCYForce1

I can give you the zip file I created in java, they are exactly the same as created by winzip. I tried to deploy the zip file both using metadata api and ant deployment tool. It both fails.

SCYForce1SCYForce1

I dont set the size and time in the Zipentry,

 

Here is the code:

 

public static File createZipFile(String zipFilename, String directory) {
		_log.info("********************************");
		_log.info("Start creating zip file");
        ZipOutputStream out = null;
        try {
			out = new ZipOutputStream(new FileOutputStream(zipFilename));
			createZipFile(new File(directory), new File(directory), out);
		} catch (IOException e) {
			_log.error("Error while creating zip file: " + zipFilename  +" - %s" + e.getMessage());
		} finally {
			if (out!=null)
            try {out.close();} catch (IOException e) {_log.error("Error while closing the writer - %s" + e.getMessage());}           
       }
		_log.info("Zip file: " + zipFilename + " has been created");
        return new File(zipFilename);
	}

private static void createZipFile(File directory, File base, ZipOutputStream out) throws IOException{   	
		byte[] buf = new byte[4096];
		InputStream in = null;
		for (File file : directory.listFiles()) {
			if (file.isDirectory()) {
				_log.info("Adding directory: " + file.getName());
				createZipFile(file, base, out);
			} else {
				_log.info("Adding file: " + file.getName());
				in = new BufferedInputStream(new FileInputStream(file), 4096);
				ZipEntry entry = new ZipEntry(file.getPath().substring(
						base.getPath().length() + 1));
				out.putNextEntry(entry);
				int len;
				while ((len = in.read(buf)) > 0) {
					out.write(buf, 0, len);
				}
			}
		}
		if (in != null) in.close();
    }

 

 

Do I need to do that?