1

I have a WSDL that I have imported in Salesforce and parsed using the WSDL2APEX option . It generates a sample message like below.

    <LineItems>
        <LineItem>
            <MaterialNumber>1938449</MaterialNumber>
        </LineItem>
        <LineItem>
            <MaterialNumber>BJ15210</MaterialNumber>
        </LineItem>
    </LineItems>

However I need to pass an attribute for the total count of the line items.

    <LineItems count="2">
        <LineItem>
            <MaterialNumber>1938449</MaterialNumber>
        </LineItem>
        <LineItem>
            <MaterialNumber>BJ15210</MaterialNumber>
        </LineItem>
    </LineItems>

Any help to achieve this is highly appreciated. Looking for guidance on how to modify the generated apex classes.

edit sample Apex class generated from the WSDL:

public class TestWsClass {
    public class Header{
        public String BatchID;        
        public TestWsClass.ArrayOfLineItem LineItems;
        private String[] BankBatchID_type_info = new String[]{'BankBatchID','http://Soap30/message/',null,'0','1','false'};        
        private String[] LineItems_type_info = new String[]{'LineItems','http://Soap30/message/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://Soap30/message/','true','false'};
        private String[] field_order_type_info = new String[]{'BatchID','LineItems'};        

    public class LineItem {
        public String MaterialNumber;
        private String[] MaterialNumber_type_info = new String[]{'MaterialNumber','http://Soap30/message/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://Soap30/message/','true','false'};
        private String[] field_order_type_info = new String[]{'MaterialNumber'};
    }
}
  • you want to add some extra value in XML you got and sent as response in the callout? – Vidhyasagaran Muralidharan May 3 at 18:37
  • Yes correct. The apex classes that are generated by importing the WSDl don't have any way for me to pass in the attribute "count" to add it to the outgoing xml message – CodeNinja May 3 at 18:44
  • Can you post the generated apex? Then we may be able to show you where to add the code – willard May 3 at 18:55
  • @willard added the sample apex code that's generated. – CodeNinja May 3 at 20:11
1

Unfortunately this is a limitation of wsdl2apex. Or more specifically, WebServiceCallout.invoke that the generated code is ultimately used with.

As you can see, the generation of an XML element in the SOAP message requires two parts in the parent class:

  1. The member to contain the actual data.
    public TestWsClass.ArrayOfLineItem LineItems;

  2. A corresponding *_type_info that contains the metadata required to generate the correct XML Element. private String[] LineItems_type_info = new String[]{'LineItems','http://Soap30/message/',null,'0','1','false'};

They are linked by a naming convention that the latter is a suffix on the members name.

XML attributes follow the same pattern, except rather than using *_type_info they use *__att_info. In your case it would look something like:

public class ArrayOfLineItem {
    // ... Existing class body
    public String count;
    private String[] count_att_info = new String[]{'count'};
}

See also:

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.