0

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 and program__r.name but it does not work (see errors below). The 'field name' of the Program Name on the Program__c object is 'name'.

Current Code:

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

Error for program__c.name

[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' ] ]

Error when using program__r.name

[InvalidSObjectFault [ApiQueryFault [ApiFault exceptionCode='INVALID_TYPE' exceptionMessage='sObject type 'Tasks' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.' extendedErrorDetails='{[0]}' ] row='-1' column='-1' ] ]

3
  • I m guessing Program__c has a Lookup field to Task, but this is not clear in your question. Please edit your question to add details of the object model. – Phil W Sep 16 '20 at 21:15
  • Also, please don't just repost a question. You should have simply edited the previous one to clarify why the original isn't a duplicate question. – Phil W Sep 16 '20 at 21:17
  • 1
    Are you saying that your Tasks are related to custom objects through the out-of-the-box Related To relationship, whose API name is WhatId? – David Reed Sep 16 '20 at 23:32
0

It seemed to work fine for me.

I had a plain custom object called Program. To which I created a Lookup relationship from Activity. The API name for that relationship was DFB__Program__c for me (I have the namespace DFB in the org I tested with).

enter image description here

The following SOQL query found a test Task on a Contact and the corresponding related Program for that Task. Note the __r relationship suffix on the lookup fields API name.

 Select Id, (Select Id, DFB__Program__r.Name from Tasks) from Contact

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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