function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brad007Brad007 

Can lists be passed to a web service method.

Hi,

 

Can lists be passed to a webservice methods. Or should they be passed as strings. If they should only be passed string whats the alternative to convert a list to a string.

 

please suggest.

 

Thank you

spraetzspraetz

Yes, you can pass strings into webservices.  Are you seeing behavior to the contrary?

 

Brad007Brad007

Can list of records be passed into a web service

Roth2842Roth2842

Doesn't that depend on the functionality of the web service?  I imagine if you can get both sides to agree on the data type, and your application can create an object of that type, then you can pass it in, but the understanding of the data both sides is the problem.

 

In the web services that I have created, when working with lists, I've just marshal the data into a CSV text string, and then pass that, and then let the receiving end "unmarshal" it..

Brad007Brad007

Great Thank you for the information. My confusion is cleared.

 

can you please provide me a sample of how Lists with records can be converted to a CSV format in APex.

 

That would be helpful

 

Thank you.

spraetzspraetz

Shouldn't your WSDL solve the problem of figuring out how to get both sides of your integration to talk to each other?

 

The WSDL should be defiing the types and how they are represented, no?

Roth2842Roth2842

Now I haven't validated this:

String csvString = 'header1,header2,header3\n';
for (Custom_Object__c co : listCustomObject){
  csvString += co.header1_field__c + ','+ co.header2_field__c + ',' + co.header3_field__c + '\n';
}

 

Roth2842Roth2842

spraetz wrote:

Shouldn't your WSDL solve the problem of figuring out how to get both sides of your integration to talk to each other?

 

The WSDL should be defiing the types and how they are represented, no?


Agreed.

 

Would that work with a partner WSDL and lists of custom objects?  I have never tested it.  When working with partners, I have always used the csv method, and never taken the time to test it out.