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
COZYROCCOZYROC 

describeSObject for query statement

Hello Guys,

 

I want to ask if there is similar to describeSObject method for describing user-specified query statement. The statement will be used with the query method? If not, what is the solution in this case?

 

Regards,

Ivan

 

COZYROCCOZYROC
I want to ask again. Isn't there solution to this issue? The statement is SOQL. Is there a method to get the metadata for the user-specified list of fields?
SuperfellSuperfell
No, you have to piece together the metadata you want from the regular describeSObject calls.
COZYROCCOZYROC

Hi Simon,

 

Thank you for the feedback! This is unfortunate. A feature like that would be necessary for better integration with third-party systems. Without it people have to built the necessary metadata manually.

 

One additional question. Is there a place where I could submit this feature request?

 

Regards,

Ivan

 

SuperfellSuperfell
http://ideas.salesforce.com/popular/force.com_platform?skin=adn
COZYROCCOZYROC

Thank you, Simon!

 

I have posted it:

 

http://ideas.salesforce.com/article/show/10098152/describeSObjectlike_method_for_SOQL_statement

 

Everybody who is interested in this functionality is more than welcome to vote on it.

 

Regards,

Ivan

 

SuperfellSuperfell
can you describe a specific usage for this?
COZYROCCOZYROC

Simon,

 

I can talk about our current situation. We have a component, which allows pulling of data from Salesforce service. The component can be then used to feed this data to a database system or to be transformed. The component exposes this data in flattened column format. We allow the user to specify either Salesforce object or SOQL statement. When the user specifies object, we use describeSObject method to retrieve its metadata and setup the data columns and data types. When the user specifies SOQL statement, we have no choice but ask the user to manually build the columns and the types based on his SOQL statement. This is the issue.

SuperfellSuperfell
I see, for now the results of the query have all the object & field names in them, so you can do a describeSObject on the relevant objects at that point to get the additional metadata. 
COZYROCCOZYROC

Simon,

 

What about if specified query returns no records? How could you get the list of fields?

SuperfellSuperfell
Right, the query needs at least 1 row of return data (but the metadata doesn't seem all that useful if there's no data)
COZYROCCOZYROC

Simon,

 

It looks like this approach is not going to work. The returned field sObject has the field name, but there is no information about the related Salesforce object.

SuperfellSuperfell
For the partner API its in the type element, for the enterprise API, its in the xsi:type of the enclosing element.
COZYROCCOZYROC
But isn't the type element per record? I'm using the SOAP proxy generated in .NET and there is type and Any properties. type is string and Any is array of XmlElement objects. There is one element per field. There is no property or attribute which relates this field to Salesforce object. And from what I understand, SOQL does support in the SELECT fieldList, fields from different objects.
SuperfellSuperfell

yes, the type is per record, but the data is returned in a per record/type format, even if you query related data, this data is returned in different objects, e.g.

 

select name, account.name from contact

 

each row in the queryResult is a contact (and the .type property on the sobject will say Contact), the Account element contains a nested account object, e.g. the xml looks like

 

<sobjects>

   <id>some ContactID</id>

   <type>contact>

   <name>Fred</name>

   <account>

      <type>account</type>

      <name>Fred Inc.</name>

   </account>

</sobject>

 

So you always know the enclosing type of a field. 

COZYROCCOZYROC

Awesome! It worked like a charm. Thank you for your patience, answering my questions Simon.