2

I want to use salesforce standard method WebServiceCallout.invoke() to send a request and parse the response. In the response I have a structure like below:

<bag>
   <item item-id="item1">STRING_CONTENT</item>
   <item item-id="item2">STRING_CONTENT</item>
</bag>

How to construct the wrapper class in order to get both item-id and STRING_CONTENT values?
WSDL2Apex produced Wrapper like below but there is no field for content!

public class Item {
    public String item_id;

    private String[] item_id_att_info = new String[]{'item-id'};
    private String[] apex_schema_type_info = new String[]{'http://www.myUri.com/model','false','false'};
    private String[] field_order_type_info = new String[]{};
}

I tried to add the content field for Item element myself (by analogy to this answer: https://stackoverflow.com/questions/4392616/what-are-the-parameters-for-the-salesforce-webservicecallout-invoke-method) but this is not working:

public class Item {
    public String item_id;
    public String content;

    private String[] item_id_att_info = new String[]{'item-id'};
    private String[] content_type_info = new String[]{null,'http://www.myUri.com/model',null,'1','1','false'};
    private String[] apex_schema_type_info = new String[]{'http://www.myUri.com/model','false','false'};
    private String[] field_order_type_info = new String[]{'content'};
}

public class Bag {
    public Item[] items;

    private String[] items_type_info = new String[]{'item','http://www.myUri.com/model',null,'0','-1','true'};
    private String[] apex_schema_type_info = new String[]{'http://www.myUri.com/model','false','false'};
    private String[] field_order_type_info = new String[]{'items'};
}

In the Bag wrapper I can define an array of string String[] items which gets the content, but in this case I'm losing the item-id.

1
  • Can you post the "Bag" class?
    – Ashwani
    Jan 19, 2017 at 16:06

1 Answer 1

1

Currently it is not possible with WebServiceCallout.invoke() to parse both node's attribute and text.

The only way out seems to manually build xml, fire http callout and parse response myself.

This is what FuseIT tool generated for me (including the warning line):

//Warning: Simple Content Types with Attributes are not supported by WebServiceCallout.invoke
public class Item {
    public String input;
    private String[] input_type_info = new String[]{'input','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
    public String item_id;
    public String[] item_id_att_info = new String[]{'item-id'};
    private String[] apex_schema_type_info = new String[]{'http://www.myUri.com/model','true','false'};
    private String[] field_order_type_info = new String[]{};
}

The FuseIT tool can generate the code to build xml and parse it but for now I'll stick to the workaround with getting only the node's text like below.

public class Bag {
    public String[] items;

    private String[] items_type_info = new String[]{'tokens','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
    private String[] apex_schema_type_info = new String[]{'http://www.myUri.com/model','false','false'};
    private String[] field_order_type_info = new String[]{'items'};
}

Similar question: Problem with Wsdl2apex with <s:extension> and value FuseIT tool

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .