We have a custom object program__c. We have a lookup field on the Tasks object to program under 'Related To'.

Below is my current query. Program__c is pulling the program code, but I want the program Name. I've tried program__c.name but it does not work. The 'field name' of the Program Name on the Program__c object is 'name'.

SELECT Salesforce_18_Digit_ID__c, firstName, lastName, email, phone, mobilePhone,
    (SELECT program__c, Id, CreatedDate FROM Tasks)
FROM Contact c

Error Message:

[InvalidFieldFault [ApiQueryFault [ApiFault exceptionCode='INVALID_FIELD' exceptionMessage=' (SELECT program__c.name, ^ ERROR at Row:11:Column:9 Didn't understand relationship 'program__c' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.' extendedErrorDetails='{[0]}' ] row='11' column='9' ] ]

  • Please clarify "does not work". Do you get an error message? If so, please edit your post to include it verbatim. You are missing a comma, so it seems like you may have pasted your query incorrectly.
    – Adrian Larson
    Sep 16 '20 at 19:21
  • Fixed the comma and added the error message
    – user78286
    Sep 16 '20 at 19:26

You join parent fields into a query using Lookup__r, not Lookup__c.

(SELECT Program__r.Name FROM Tasks)

Not the answer you're looking for? Browse other questions tagged or ask your own question.