I'm trying to get apex code body by invoking metadata soap api in apex code. I invoked retrieve method, got and resolved response. But in response, i found everything except apex code body, i couldn't get any idea about this, who knows this issue? Please help! Thanks in advance.

       string soapBodyForRetrieve = 
       '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
           '<SOAP-ENV:Header>' +
               '<m:SessionHeader xmlns:m="http://soap.sforce.com/2006/04/metadata">' +
                   + '<m:sessionId>' + Userinfo.getSessionId() + '</m:sessionId>' +
               '</m:SessionHeader>' +
           '</SOAP-ENV:Header>' +
           '<SOAP-ENV:Body>' +
               '<m:retrieve xmlns:m="http://soap.sforce.com/2006/04/metadata">' +
                   '<m:retrieveRequest>' + 
                       '<m:unpackaged>' +
                           '<m:apiAccessLevel>Unrestricted</m:apiAccessLevel>' +
                           '<m:namespacePrefix>LWG</m:namespacePrefix>' +
                           '<m:types>' +
                               '<m:members>SoapController</m:members>' +
                               '<m:name>ApexClass</m:name>' +
                           '</m:types>' +
                           '<m:version>33</m:version>' +
                       '</m:unpackaged>' +
                   '</m:retrieveRequest>' +
               '</m:retrieve>' +
           '</SOAP-ENV:Body>' +
    return soapBodyForRetrieve;
  • 1
    Please show more of your code, so that we see your callout and how you poll the async request. Also add your response (xml dump).
    – Uwe Heim
    Apr 5 '15 at 9:49
  • The metadata only contains the info about the class. To actually get the code, you have to use the retrieve method which gets it as a file that you would need to parse. The tooling API may be what you want. salesforce.com/us/developer/docs/api_toolingpre/api_tooling.pdf
    – CyberJus
    Apr 5 '15 at 21:38
  • Hi, i solved this issue by referencing some javascript plugins. Please check my answer. Thanks anyway. :)
    – Allen Li
    Apr 7 '15 at 10:34

After lots of research, i found we have to reference jszip.js, jszip-load.js, jszip-inflate.js, jszip-deflate.js in javascript, otherwise the compression content will be lost when we parse zip file(base64).

We can find these plugins by this link: https://code.google.com/p/webpagetest/source/browse/trunk/agent/js/node_modules/node-zip/vendor/jszip/?r=1556

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.