I have a inbound webservice written in Apex. When I am generating the WSDL file and validating the Request XML format I see a flat XML structure. This is not what am expecting. I would like to have the below structure, this am not sure how can I code to achieve this in my inbound webservice. In the below structure, there can be multiple accounts and there corresponding contacts in the list.
I have also mentioned the couple of ways have tried on the class but it doesn't give the below structure what would be you advice?
<listAccount>
<account>
<AccountID>123</AccountID>
<AccRating>A</AccRating>
<Contact>
<ContactId>234</ContactId>
<FullName>Henry</FullName>
<Email>H@gmail.com</Email>
</contact>
</account>
<account>
<AccountID>893</AccountID>
<AccRating>A</AccRating>
<Contact>
<ContactId>294</ContactId>
<FullName>Henry1</FullName>
<Email>H1@gmail.com</Email>
</contact>
</account>
</ListAccount>
Instead am getting either of the below structure:
<listAccount>
<AccountID/>
<AccRating/>
</listAccount>
or
<Contact>
<ContactId/>
<FullName/>
<Email/>
</Contact>
I tried to modify my webservice as below: and it keeps failing
global class AccounContact
{
global class AccountMsgSendToSF
{
webservice AccountID ;
webservice AccRating;
global Class ContactMsgSendtoSF
{
webservice ID ContactId
webservice string FullName;
webservice string EMail;
}
}
webservice static method () {}
}
OR
if i try the below way: it just hides the Contact section from the XML structure
global class AccounContact
{
global class AccountMsgSendToSF
{
webservice AccountID ;
webservice AccRating;
ContactMsgSendtoSF Csf = new ContactMsgSendtoSF();
}
global Class ContactMsgSendtoSF
{
webservice ID ContactId
webservice string FullName;
webservice string EMail;
}
webservice static method () {}
}
Best Answer
Your provided code isn't valid and can not produce either one of the examples which you demonstrated as results of what is generated. It's a lot easier to assist when you provide a reproducible problem.
Below is a working example that supports the structure you're intending and also demonstrates the service payload. Hopefully you can adapt it to your needs.
Apex
getData() SOAP Response