+ Start a Discussion
jteam12jteam12 

Web Service Result - Returned to Auto Created APEX Objects

I have imported a WSDL, Force.com has generated the classes, including several custom data type objects.  I can invoke the service and in the Force.com IDC using Execute Anonymous, I can see that the returned XML is what I expect.

 

But now I am having trouble figuring out how to get the results out of the response object.

 

The response message is structured something like the example below.  It is a query into an ERP system about product master data.

 

<response>

<material>

<ID>

<some property1 />

<some property2 />

</ID>

<description>

<some property3 />

</description>

</material>

</response>

 

The nodes that I want to get the values of are the ID and description nodes.  In my case, the levels beneth the ID and description notes are empty as a result of my request to the service.  So the response looks something like this:

 

<response>

<material>

<ID>123</ID>

<description>Some Material</description>

</material>

</response>

 

The APEX class that was generated from the WSDL has created <ID> and <description> each as classes, rather than primitives because each has lower level attributes.  

 

So the classes look something like this:

 

class response{

material mat;

}

 

class material{

ID internalID;

description desc;

}

 

class ID{

String some_property1;

String some_property2;

}

.

.

.

 

 

So, how do I access the value of the <ID> and <description> nodes from the response message?  

 

Another question: how can I view the content of the response object itself?  Is there a perspective in the Force.com IDE to view this?  I've used Flex Builder before and it lets you give the content of an object while debugging your code.  That would be helpful here so that I can see exactly how Force is building out the response object form the response message.

SuperfellSuperfell

res.mat.internalId.some_property1;

res.mat.description;

jteam12jteam12

Simon,

 

Thanks for the quick reply, but that doesn't really solve it. 

 

First, the node that I want to access is the ID node and not the ID.some_property1 node.  Next, if I try to access the res.mat.description node, that references an object (because description is an object).  So my question is how do I retrieve the value at the ID level rather than at a next level down.

 

I think that if both ID and description were primitives, then what you suggest would work perfectly.  The difficulty seems to be that they are objects rather than primitives.  

 

 

SuperfellSuperfell

What does the WSDL look like ?

jteam12jteam12

Here are a few sections of the WSDL:

 

 

- <xsd:complexType name="MatlCRMBscDataByElmntsRsp_sProd"> //equal to what I was calling material above
- <xsd:sequence>
  <xsd:element name="Common" type="MatlCRMBscDataByElmntsRsp_sCom" minOccurs="0" />
  <xsd:element name="BaseProductCategory" type="MatlCRMBscDataByElmntsRsp_sProdBaseCat" minOccurs="0" />
  <xsd:element name="SalesProcessUsability" type="MatlCRMBscDataByElmntsRsp_sProdSts" minOccurs="0" maxOccurs="unbounded" />
  <xsd:element name="MainAlternativeID" type="MatlCRMBscDataByElmntsRsp_sAlternativeID" minOccurs="0" />
  <xsd:element name="InternalID" type="ProductInternalID" minOccurs="0" />
  <xsd:element name="Description" type="SHORT_Description" minOccurs="0" />
  <xsd:element name="ProductTypeCode" type="ProductTypeCode" minOccurs="0" />
  <xsd:element name="SourceBusinessSystemID" type="BusinessSystemID" minOccurs="0" />
  </xsd:sequence>
  </xsd:complexType>

 



- <xsd:complexType name="ProductInternalID"> //equal to what i was calling ID above
- <xsd:annotation>
- <xsd:documentation xml:lang="EN">
  <ccts:RepresentationTerm>Identifier</ccts:RepresentationTerm>
  </xsd:documentation>
  </xsd:annotation>
- <xsd:simpleContent>
- <xsd:extension base="ProductInternalID.Content">
- <xsd:attribute name="schemeID">
- <xsd:simpleType>
- <xsd:restriction base="xsd:token">
  <xsd:maxLength value="60" />
  <xsd:minLength value="1" />
  </xsd:restriction>
  </xsd:simpleType>
  </xsd:attribute>
- <xsd:attribute name="schemeAgencyID">
- <xsd:simpleType>
- <xsd:restriction base="xsd:token">
  <xsd:maxLength value="60" />
  <xsd:minLength value="1" />
  </xsd:restriction>
  </xsd:simpleType>
  </xsd:attribute>
  </xsd:extension>
  </xsd:simpleContent>
  </xsd:complexType>
- <xsd:simpleType name="ProductInternalID.Content">
- <xsd:restriction base="xsd:token">
  <xsd:maxLength value="60" />
  <xsd:minLength value="1" />
  </xsd:restriction>
  </xsd:simpleType>
- <xsd:simpleType name="ProductTypeCode">

 



jteam12jteam12

Quick update, though the problem isn't solved:

 

I changed the generated classes (from importing the WSDL) as follows and I can access the response variables using the dot operator (such as response.material.ID):

 

Original:

class response{

material mat;

}

 

class material{

ID internalID;

description desc;

}

 

class ID{

String some_property1;

String some_property2;

}

.

.

.

 

Changed:

 

class response{

material mat;

}

 

class material{

String internalID; //changed type to String from ID class

String desc;  //changed type to String from description class

}

 

class ID{

String some_property1;

String some_property2;

}

.

.

.

 

But this hasn't really solved my problem since the generated classes don't really work correctly (or at least how I expect them to.

 

So, again, my basic question is, if I have a web service response like:

<root>

<level 1>

<level 2.1 />

<level 2.2 />

</level 1>

</root>

 

How can I access the value assigned at <level 1>?

 

For example, say the response is: <root><level 1>Value of Level 1</level 1></root>, how do I get at "Value of Level 1"?  It seems like perhaps the classes generated from importing the WSDL are not correct but I'm not sure how to modify them to make them work.  The modification that I made above isn't a good solution because I lose the value of <level 2.1> and <level 2.2>.

 

Any help will be appreciated.