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
TesterInSkyTesterInSky 

What type should be if there are more then one 'referenceTo' returned in 'describeSObjects' call

When calling 'describeSObjects' in Java to get the sObject fields information to form the concrete schema on local, I  noticed that the type returned as 'referenceTo' for some sObjects may have more than one 'referenceTo' node. Thus I was confused how could I set referece type for such kind of fields.
 
my question is:
    1. Base on my analysis, I noticed that there are many fields may have more then one 'referenceTo', please confirm me whether I was right.
    take the sObject 'ActivityHistory' for example, there is a field named 'What' with the type of 'ens:Name', but in the soap message there are more than one 'referenceTo' node including the 'ens:Asset' among these 'referenceTo' nodes, which you may noticed that it is neither a 'ens:User' nor a 'ens:Group'. I also saw some other sObject names (the field 'Who' in 'ActivityHistory' is set to 'ens:Name' as its type, but with more than one reference To including 'ens:Contact' ) appeared in this 'referenceTo'.

    2. If the No.1 above can be confirmed, then I would like to know is this muti-referenctTo thing only relates to 'ens:User'? I mean is it correct if I set the type for all fields who have more than one 'referenceTo' node derectly to 'ens:Name'?
 
Thanks
SuperfellSuperfell
Yes, there can be FK fields that can be references to more than one type. this manifests itself as multiple types returned in the referenceTo list.

the relationship for these fields are modled as pointing to the name entity (see the namePointing flag in the describe docs), when you run SOQL-R queries against these relationships, you can only query fields from the name entity.


Sorry, i don't follow your 2nd question at all. User has nothing to do with it (other than lots of relationships point to User). I don't know what you mean by setting the type to Name, whether you use Name, or you use some concrete type depends on exactly what you're trying to do.
TesterInSkyTesterInSky
Thank you Simon
 
I asked the 2nd question because I want to form a concrete xml schema file for all the sObject. So I need to know what value should I put in the 'type' attribute of those fields who have more than one 'referenceTo' node.
 
I want to set the type of all these fields to 'Name' is because, I analyzed the Enterprise WSDL, and noticed that, take the field 'Owner' in the sObject 'ActivityHistory' for example, two 'referenceTo' nodes (with the value 'User' and 'Group') returned by the 'describeSObjects' call for this field, and in the Enterprise WSDL, the type has been set to 'Name'. I also checked some other fields with muti-referenceTo nodes returned, it has also been set to 'Name'.
 
So I wonder if 'Name' can be seen as a 'shared' sObject which can accept data from different sObjects at runtime.
SuperfellSuperfell
No it does not, you need to use the real concrete type for a create/update/upsert call etc. (but, the relationship is only used to resolve FK values via external Ids fields, so you may not need it at all).
TesterInSkyTesterInSky
Hi Simon,
 
Actually I do not want to use the real concreate type for a create/update/upsert call etc.
 
What I required to do is to write java code to generate a xsd file on my local with all the sObject schema definition in it, just like the schema definition in the Enterprise WSDL.  Take a piece of code copied from Enterprise WSDL for example:
 
Code:
<complexType name="AccountHistory">
                <complexContent>
                    <extension base="ens:sObject">
                        <sequence>
                            <element name="Account" nillable="true" minOccurs="0" type="ens:Account"/>
                            <element name="AccountId" nillable="true" minOccurs="0" type="tns:ID"/>
                            <element name="CreatedBy" nillable="true" minOccurs="0" type="ens:Name"/>
                            <element name="CreatedById" nillable="true" minOccurs="0" type="tns:ID"/>
                            <element name="CreatedDate" nillable="true" minOccurs="0" type="xsd:dateTime"/>
                            <element name="Field" nillable="true" minOccurs="0" type="xsd:string"/>
                            <element name="IsDeleted" nillable="true" minOccurs="0" type="xsd:boolean"/>
                            <element name="NewValue" nillable="true" minOccurs="0" type="xsd:anyType"/>
                            <element name="OldValue" nillable="true" minOccurs="0" type="xsd:anyType"/>
                        </sequence>
                    </extension>
                </complexContent>
            </complexType>

In my own code, when creating the element 'CreatedBy' and trying to set value for its 'type' attribute, what I got from the describeSObjects call is that there are more than one item in the 'referenceTo' array with 'User' and 'Group' in it. So I do not know what value should I set to this 'type' attribute. Is there a way to fix this?
 
Thanks
SuperfellSuperfell
if the field says namePointing, then it can be name. but (a) you could just extract the schema from the WSDL, its probably a trivial task in XSLT. (b) a schema on its own isn't very useful, what are you going to do with it once you've generated it ?
TesterInSkyTesterInSky
Thanks for your reply.
 
So you mean if a field's 'namePointing' value is 'true', then I could set the field type to 'ens:Name' ( 'ens:Name' is another defined sObject type)?
 
Actually, I form the concrete schema file for Partner wsdl, and want to have some other functions being created based on it.
SuperfellSuperfell
yes namePointing means the Name entity is used for queries on that relationship.

Why don't you just use the enterprise API?, it sounds like you're just rebuilding it from the partner API.