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
Nitin PalmureNitin Palmure 

unable to fetch parent field from child Object using soql

Hello,

I have created a Child object Demand_Campaign__c having master detail relationship with account.
Now when I am trying to query to get Account information using following query, Developer console is giving me error.

Query: SELECT Id, Account.Name from Demand_Campaign__c
Error:
SELECT Id, Account.Name from Demand_Campaign__c
           ^
ERROR at Row:1:Column:12
Didn't understand relationship 'Account' 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.

Request you to please help.

Regards,
Nitin V Palmure
 
Best Answer chosen by Nitin Palmure
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Nitin Palmure:

  Account.Name,AccountId ... is the field representation used in soql  only in case of standard relationships,for eg., you can use Select Account.name from contact  or select Account.Name from Opportunity etc. where Account,Contact,Opportunity were standard objects and relationship between them is the Out of box realationship.

In case of  custom relationships, '__r' should be appended in order to access the parent records field information via soql, for eg., let us assume Account__c is api name for the Master Detail field on Demand_Campaign__c, in that case:

select Account__r.Name from Demand_Campaign__c is the syntax that needs to be used to pull info from Account.

Hope this clarifies:

Thanks,
balaji