One Star

Salesforce Relationship SOQL Query not returning related fields

I'm trying to run a manual SOQL query in a simple job with these components: tSalesforceInput --> tLogRow
The query:
SELECT Name, BillingStreet, Owner.Name, (SELECT Name, Phone,MobilePhone FROM Contacts WHERE Primary__c=true) FROM Account WHERE Status__c = 'Active Customer'
The background:
I can run this query in Salesforce's Workbench and it returns records with values in each field. In tSalesforceInput I've defined my schema as (all strings):
Name
BillingStreet
Owner_Name
Contacts_Name
Contacts_Phone
Contacts_MobilePhone
The problem:
I get all the expected records back, however no values are visible in the Contacts_Name, Contacts_Phone and Contacts_MobilePhone fields. The first three fields are populated as expected. 
Does anyone know how to return values in a relationship query like this one? I suspect that the field name in the schema is important, but I haven't been able to figure it out. 
Thanks in advance for any help!
Mike
3 REPLIES
Moderator

Re: Salesforce Relationship SOQL Query not returning related fields

Hi,
Have you tried to add the '__c' on the column name on schema. Note that the filed name is case-sensitive.

Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Salesforce Relationship SOQL Query not returning related fields

In this case all the fields are native Salesforce so there is no need for the __c. I did try every variant I could think of for the field names in the schema since I know they have to be formatted correctly. In the example I listed Owner_Name the Parent query field (Owner.Name = Owner_Name) works fine but I haven't been able to crack the code on the child query fields. Any help appreciated. 
One Star

Re: Salesforce Relationship SOQL Query not returning related fields

Agreed, this does not work with Parent-to-child queries like this.  I have also tried all combinations.
If you change the query to Child-to-parent, then it works with the "parent_" prefix for your schema.  But doing it that way will NOT get you those parents that do not have any children.  The only way to get that, is with the parent-to-child query like the one shown.  
Or, to make multiple passes and tJoin/tMap.