2

I have created apex stub classes from a wsdl and invoked a external SOAP webservice from it. The response is an xml with attribute in elements. I need to extract the value (which is 'PPPPPP' when wd:type="Item_ID" in below xml

<wd:Sales_Item_Reference>
     <wd:ID wd:type="WID">9d89472a929901c34895bc41a6259610</wd:ID>
     <wd:ID wd:type="Item_ID">PPPPPP</wd:ID>
</wd:Sales_Item_Reference>

These are the corresponding stub class methods generated

//for Sales_Item_Reference
public class Sales_ItemObjectType {
        public SOAPStub.Sales_ItemObjectIDType[] ID;
        private transient String[] ID_type_info = new String[]{'ID',s_ns0,'Sales_ItemObjectIDType','0','-1','false'};
        public String Descriptor;
        public String[] Descriptor_att_info = new String[]{'Descriptor'};
        private transient String[] apex_schema_type_info = new String[]{s_ns0,'true','false'};
        private transient String[] field_order_type_info = new String[]{'ID'};
}

//For ID
public class Sales_ItemObjectIDType {
        public String input;
        private transient String[] input_type_info = new String[]{'input','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        public String type_x;
        public String[] type_x_att_info = new String[]{'type'};
        private transient String[] apex_schema_type_info = new String[]{s_ns0,'true','false'};
        private transient String[] field_order_type_info = new String[]{};
}

Sales_ItemObjectIDType.type_x gives me the attribute value 'Item_ID' but how do I retrieve the value 'PPPPPP'

1

Based on your example response of:

<wd:Sales_Item_Reference>
     <wd:ID wd:type="WID">9d89472a929901c34895bc41a6259610</wd:ID>
     <wd:ID wd:type="Item_ID">PPPPPP</wd:ID>
</wd:Sales_Item_Reference>

I'd expect to access the Element value of PPPPPP via Sales_ItemObjectIDType.input. This isn't the elements attribute, but rather its value.

Something like this:

Sales_ItemObjectType calloutResponse = // the result from some callout
for(Sales_ItemObjectIDType objectType : calloutResponse.ID) {
    if(objectType.type_x == 'Item_ID') {
        System.debug('Item_ID is ' + objectType.input);
    }
}
2
  • Thanks for your reply. But I tried that already and I get a null value. When I do the same callout using postman, I get values back. So, null is not right Jan 6 at 14:07
  • Can you provide the CALLOUT_RESPONSE from the debug log? It would appear that the XML SOAP response isn't being deserialized in the Apex objects correctly. Jan 8 at 1:29

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.