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
viodevviodev 

SOQL metadata through web service API

I am using Apache Axis to access the Web Services API.  However, I believe my question is not specific to the Java API, and is applicable to all Web Service clients.

I am using the partner.wsdl Version 16.0.

Is there a way for a Web Service query() method call to return the metadata of the SOQL query?  Specifically, the fields that were requested in joined object.  My issue is that if the joined object has no rows, then all I get back in the SOAP message is an empty object.

For example:
    I have two Account objects: with name/billingcity "Acct A"/"Boston" and "Acct B"/"New York".
    And "Acct A" has two Contact objects, but "Acct B" has no Contact objects.

If I query for:
    select a.Name, a.BillingCity, (Select Email, LastName From Contacts) from Account a where a.Name = 'Acct A'
I will get back the Name and BillingCity of the Account, along with the Email and LastName of both the Contacts.  From this data, I can interpret that the SOQL query asked for these four fields.

However, If I query for:
    select a.Name, a.BillingCity, (Select Email, LastName From Contacts) from Account a where a.Name = 'Acct B'
I will get back the Name and BillingCity of the Account, along with an empty Contact XML node.  From this data, I have no way of knowing the SOQL query asked for Contact Email and LastName.

I need this metadata to present back to my client the list of fields that they requested, even if the object/fields are null.

Is there a way for me to get this metadata?

thanks!

Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf
I think your only option is to parse the query.  It seems a fair bet that you can use a simple regex to exclude anything that looks like it's not a straight-up field.

All Answers

werewolfwerewolf
But you already have that list -- it's in the call to query() that you just sent!  Why would you not just pull the fields right out of the query text?
viodevviodev

Thanks for the suggestion.

 

Since my code does not create the SOQL query, I would need to parse the SOQL query string that is given to me. This is an option.  However, as Salesforce develops the SOQL syntax further, I would need to update the parsing in my application to keep up with the specification.

 

For example, if Salesforce added some of the functions you see in SQL (union/min/max/decode) or more complicated subselects, the query parsing would become more complicated.

 

Since Salesforce is the owner of the SOQL specification, and already parses the query request, I would guess that it is possible to return that information to the requestor.  This would be similar to what you get from a JDBC call.

 

Does this make sense?

werewolfwerewolf
I think your only option is to parse the query.  It seems a fair bet that you can use a simple regex to exclude anything that looks like it's not a straight-up field.
This was selected as the best answer
viodevviodev
I think I will parse the query for now, and hope that Salesforce decides to add the metadata in a future release.  Thanks for your help!
COZYROCCOZYROC

I have the same problem. I have posted suggestion to Salesforce to implement enhancement to their API here.