certinia / apex-mdapi

Apex Wrapper for the Salesforce Metadata API
BSD 3-Clause "New" or "Revised" License
685 stars 975 forks source link

This is a question - maybe an issue with new Spring '14 call #23

Closed gwarburton closed 10 years ago

gwarburton commented 10 years ago

There is a new CRUD call in Spring '14 / API 30 named "readMetadata" (http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_readMetadata.htm).

I expect this is an implementation error but since it's a new call I thought my challenge was worth reporting.

I think in my instance the SFDC parser was failing to recognize the response as the CustomField class extending Metadata.

Error message: Web service callout failed: Unable to parse callout response. Apex type not found for element externalId

Here's the raw soap response up until the point of failure ''' <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; <soapenv:Body> <readMetadataResponse> <result> <records xsi:type="CustomField"> <fullName>Case.Custom_Field__c</fullName> <externalId>false</externalId> '''

And the apex classes for the parsing ''' public class readMetadataResponse_element { public SFDC_API_MetaData.ReadResult result; private String[] result_type_info = new String[]{'result','http://soap.sforce.com/2006/04/metadata','ReadResult','1','1','false'}; private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/2006/04/metadata','true','false'}; private String[] field_order_type_info = new String[]{'result'}; } public class ReadResult { public SFDC_API_MetaData.Metadata[] records; private String[] records_type_info = new String[]{'records','http://www.w3.org/2001/XMLSchema','Metadata','0','-1','false'}; private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/2006/04/metadata','true','false'}; private String[] field_order_type_info = new String[]{'records'}; } public virtual class Metadata { public String fullName; private String[] fullName_type_info = new String[]{'fullName','http://www.w3.org/2001/XMLSchema','string','0','1','false'}; private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/2006/04/metadata','true','false'}; private String[] field_order_type_info = new String[]{'fullName'}; } public class CustomField extends Metadata { public String type = 'CustomField'; public String fullName;
[...] public Boolean externalId; [...] private String[] type_att_info = new String[]{'xsi:type'};
[...] private String[] externalId_type_info = new String[]{'externalId','http://www.w3.org/2001/XMLSchema','boolean','0','1','false'}; [...] } '''

Adding "public boolean externalId;" to the Metadata class results in the next field being reported as missing. I think the instruction to create CustomField instances is in the "xsi:type='CustomField'" attribute of the tag, which uses a different namespace (which you can see I've been fiddling with).

afawcett commented 10 years ago

Yes this is a challenge for this Apex Metadata API wrapper for Spring'14 for sure! I hit this in my Spring'14 pre-release org. Once the Salesforce Spring'14 rollout is complete i plan to rollout my solution to this problem formally to this repo. You can read a little about the preview i made of this here.

In the meantime you can see a preview of the MetadataService.cls which supports Layout (and recently WorkflowAlert in response to another question here). Once I roll it out to the repo I have an automated script that adjusts the whole MetadataService.cls and metadata types to support readMetadata. I can update the preview one to support CustomObject in the meantime if you cannot wait, let me know.

gwarburton commented 10 years ago

Thank. You. A) I'm glad to know it's a "known issue" and B) I wish I had found your blog post earlier.