I have a requirement where I need to fetch list of objects present on another Org. I tried it using metadata service but could not fetch.Any Idea how this can be done using Partner WSDL or ToolsLink API. I am pasting my sample code using metadta service.

public void fetchMetadata()
        a = TestMetadata.createService();
        MetadataService.DescribeMetadataResult describeRes = new MetadataService.DescribeMetadataResult();
        describeRes = a.describeMetadata(29);
        List<MetadataService.DescribeMetadataObject> objectList = describeRes.MetadataObjects;
         if (objectList.size() > 0) {
            for (MetadataService.DescribeMetadataObject obj : objectList) {


The metadata API isn't for retrieving records, it is for retrieving information about the structure of those records. E.g. what fields are on a custom object and what data type each field is.

The partner API isn't really intended for consumption from Apex. It includes a number of schema features that aren't supported by Wsdl2Apex.

One of these is the any element on the complexType sObject. This is important, as it is this element that would contain the sObject fields (beyond the Id) when retrieved via a SOQL query.


This will work if you have at least one Account in the target org and have the remote site settings setup to include https://login.salesforce.com and https://targetOrgPod.salesforce.com

partnerSoapSforceCom.Soap partner = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult lr=partner.login('test@example.com', 'myPasswordInPlainText!PlusTheSecurityToken');
partnerSoapSforceCom.SessionHeader_element header=new partnerSoapSforceCom.SessionHeader_element();
partner.endpoint_x = lr.serverUrl;
partnerSoapSforceCom.QueryResult qr = partner.Query('Select Id from Account limit 1');
System.debug('Number of Query results:' + qr);
sobjectPartnerSoapSforceCom.sObject_x result1 = qr.records[0];

However, if you add anything to the returned field set beyond Id you will get an error due to the missing any element. Here is what happens when I try the SOQL Select Id, Name from Account limit 1.

System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element Name: Class.DFB.partnerSoapSforceCom.Soap.query: line 2048, column 1 AnonymousBlock: line 7, column 1 AnonymousBlock: line 7, column 1

You could potentially use the Enterprise WSDL, which will include explicit elements for each field. It won't be able to dynamically handle changes in schema though.

You might be better served by an alternative method of retrieving the data, such as:

| improve this answer | |
  • @Sonal. I'm glad it worked. Which solution did you go with? Also, there is a green tick towards the top of the answer that can be used to indicate it as such. This makes the answer clearer to future users. – Daniel Ballinger Apr 6 '14 at 22:00

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.