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
PNSPNS 

Reading individual values from a QueryResult in the Enterprise API

Hi...

 

I am trying to figure out whether there is a way of accessing field values after a Web Services Enterprise API query in a generic way, i.e. without having to cast each record to a specific SObject type.

 

Example Java code:

 

 

String queryString = "SELECT Id, Name FROM Account";

SObject[] records = binding.query(queryString).getRecords();

 

 

After successfully executing the query, a number of records (Account rows) are stored in the SObject[] array, so I can get to each record via just walking through the array and reading the corresponding SObject.

 

However, the only for accessing the corresponding field values (e.g., Id, Name above) seems to be via casting, like

 

 

Account account = (Account)records[0];

 

and then invoking the corresponding API methods (e.d., account.getId() to get the value of the ID field.

 

This, however, means that I have to use a different casting for each of the (potentially hundreds) of objects in the Salesforce datastore.

 

The Partner API offers a handy get_any() method that returns Axis MessageElement objects, which encapsulate the actual field values.

 

 

So, is there any way of accomplishing the same in the Enterprise API

 

SuperfellSuperfell

You can use reflection, but its easier to use the partner API, any particular reason you don't want to ?

PNSPNS

Hi Simon...

 

Thanks for the reply! I wouldn't like to use reflection and yes, I am leaning towards the Partner API, for numerous reasons, including this one.

 

Out of curiosity, what is the technical reason for not having a call like get_any() in the Enterprise API? I would have thought it easier to implement such a call in a strongly typed environment.

SuperfellSuperfell

Remember that the client code, and the client programming model are dictated by the toolkit you choose to use to parse the WSDL, the WSDL itself does not control the programming model. (you can see this in the differences between the client model between axis1 & axis2 etc). So the reason there's no get_any() in a client built from the enterprise WSDL, is that no one building toolkits has offered it.

PNSPNS

Obviously noone has offered it yet, but that was my question: how come? :-)

 

Anyway, I am playing with the Partner API now, so this is not an issue.

 

Thanks for the information!