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
LemingtonLemington 

SOQL Syntax

We are running a relationship SOQL query (Account and Contact) which both have a FAX field.  We have tried to alias the field names to distinguish the two fields without success.  In the queryresult set, we can correctly reference one field through the "FAX" field name.  Question:  How do we reference the other FAX field?
 
Also, if there is a good SOQL reference, could you please point us in the right direction. 
 
Thank you.
XifierXifier
Can you post the text of your query here?  I suspect the answer will be something like "refer to the foreign fax field by qualifying it with its foriegn object name" -- so something like Account.Fax instead of just Fax.
LemingtonLemington

Query text is below.  We tried many combinations of "Account.Fax", "Contact.Account.Fax", FAX1, FAX2, FAX_1, etc., without success.   The Phone and Category fields will require a similar solution.

 

SELECT Contact.Account.Name, Contact.Account.Phone, Contact.Account.Fax, Contact.Account.Category__c, Contact.Salutation, Contact.FirstName, " & _
            "Contact.LastName, Contact.Title, Contact.MailingStreet, Contact.MailingCity, " & _
            "Contact.MailingState, Contact.MailingPostalCode, Contact.MailingCountry, " & _
            "Contact.Phone, Contact.MobilePhone, Contact.Fax, Contact.Email, Contact.Category__c FROM Contact

SuperfellSuperfell
You should read through the api docs on SOQL-R, unlike SQL, a relationship query does not flatten the results into a table, you get a heirarchical set of objects back, so there's no need for aliasing.
LemingtonLemington
I have referenced the API docs, though I won't admit to have read the entire documents.  We can access the Contact.Account.Name and Contact.Fax field values without using a hierarchy.  The documentation of pertaining to aliases does refer to "field name", however, we could not find the proper syntax.
SuperfellSuperfell
There are no field alias's in SOQL, only object aliases.

if you have a query
select Fax, Account.Fax from contact

then typically you'd access these fields by doing
Contact c = (Contact)qr.getRecords()[0];
c.getFax();
and
c.getAccount().getFax();

The exact syntax will depend on what soap client & language you're using.
LemingtonLemington
Simon, thank you for your response.
 
We are using the Office Toolkit but pointing at the 8.0 server URL to take advantage of the relationship syntax.  Appears to work fine, if we can find a way to reference the fields correctly. 
SuperfellSuperfell
Won't work, the office tooklit has no concept of the nested SObjected needed by a SOQL-R response.