5

Consider:

<apex:page applyHtmlTag="true">
    <apex:includeScript value="{!$Resource.Jsforce}"/>
    <input type="file" id="input"></input>
    <script type="text/javascript">
        function ctrlRead(){
            var selectedFile = document.getElementById('input').files[0];
            var files = selectedFile.files;
            var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}'});
            conn.metadata.retrieve(files,function(error,ref) {
                if (error) {
                   console.log("error");
                }
                else {
                    console.log(JSON.stringify(ref));
                }
            });
        }
    </script>
    <apex:form>
        <div>DEPLOYMENT TOOL</div>
        <apex:commandButton onclick="ctrlRead();" value="Reterive" id="theButton"/>
    </apex:form>
</apex:page>

I am trying to pass the file to the retrieving metadata API call using JSFORCE to extract the metadata. But I am getting the error

"INVALID_CROSS_REFERENCE_KEY: No packages or unpackaged specified"

How can I fix this problem?

Here is the next attempt and updated code.

I modified the code and tested it:

<apex:page applyHtmlTag="true">
    <apex:includeScript value="{!$Resource.Jsforce}"/>
    <input type="file" id="input"></input>
    <script type="text/javascript">
        function ctrlRead(){
            var selectedFile = document.getElementById('input').files[0];
            var files = selectedFile.files;
            var para = {apiVersion:37.0,packageNames:null,singlePackage:true,specificFiles:files,unpackaged:files};
            var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}'});
            conn.metadata.retrieve(para,function(error,ref) {
                if (error) {
                   console.log("error");
                }
                else {
                    console.log(JSON.stringify(ref));
                }
            });
        }
    </script>
    <apex:form >
        <div>DEPLOYMENT TOOL</div>
        <apex:commandButton onclick="ctrlRead();" value="Reterive" id="theButton"/>
    </apex:form>
</apex:page>

But now I am getting an error:

INVALID_CROSS_REFERENCE_KEY: More than 1 package retrieved with single package flag

This is the modified one i am getting success response

<apex:page applyHtmlTag="true">
<apex:includeScript value="{!$Resource.Jsforce}"/>
<input type="file" id="input"></input>
 <script type="text/javascript">
     function ctrlRead(){ 
        var selectedFile = document.getElementById('input').files[0];
        var files = selectedFile.files; 
        var para = {apiVersion:37.0,singlePackage:false,unpackaged:files};
         var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}'});
         conn.metadata.retrieve(para,function(error,ref) {
             if (error) {
                console.log("error");
             } 
             else {
                 console.log(JSON.stringify(ref));

             } 
      });
     }        
  </script>
 <apex:form >
 <div>DEPLOYMENT TOOL</div>
 <apex:commandButton onclick="ctrlRead();" value="Reterive" id="theButton"/>
 </apex:form>
 </apex:page>
2
  • What's the file you're using?
    – sfdcfox
    Commented Oct 9, 2016 at 2:34
  • I am using the package.xml file which contains this following content:<?xml version="1.0" encoding="UTF-8"?> <Package xmlns="soap.sforce.com/2006/04/metadata">; <types> <members>Loan</members> <name>FlexiPage</name> </types> <version>29.0</version> </Package Commented Oct 9, 2016 at 2:44

1 Answer 1

3

From the metadata documentation for the retrieve call in SFDC, metadata requires any of the below.

  1. Package name or list of packages you want to retrieve the metadata info for

  2. A package.xml consisting of the list of file names to retrieve

I guess in your case you should create a retrieve Request object which will be pointed to the package.xml file.

The working code is as below.

<apex:page applyHtmlTag="true">
    <apex:includeScript value="{!$Resource.Jsforce}"/>
    <input type="file" id="input"></input>
    <script type="text/javascript">
        function ctrlRead(){
            var selectedFile = document.getElementById('input').files[0];
            var files = selectedFile.files;
            var para = {apiVersion:37.0,singlePackage:false,unpackaged:files};
            var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}'});
            conn.metadata.retrieve(para,function(error,ref) {
                if (error) {
                    console.log("error");
                }
                else {
                    console.log(JSON.stringify(ref));
                }
            });
        }
    </script>
    <apex:form >
        <div>DEPLOYMENT TOOL</div>
        <apex:commandButton onclick="ctrlRead();" value="Reterive" id="theButton"/>
    </apex:form>
</apex:page>
4
  • I am using the package.xml file which contains this following content:<?xml version="1.0" encoding="UTF-8"?> <Package xmlns="soap.sforce.com/2006/04/metadata"> <types> <members>Loan</members> <name>FlexiPage</name> </types> <version>29.0</version> </Package> Commented Oct 9, 2016 at 2:42
  • Mohit, you mean to say javascript object or apex wrapper retrieve Request object and pass it to reterive call? Commented Oct 9, 2016 at 2:52
  • Yes so you will need to use a javascript object to pass that as a parameter .The request object in JSforce might need you to specify unmanaged .I would console.log the function and figure what is the expected request object format Commented Oct 9, 2016 at 3:12
  • I will dig into repo in a while and may add some more explanation Commented Oct 9, 2016 at 3:12

You must log in to answer this question.

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