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

APEX controller how to query for relationship fields



I've created a custom page that queries an account and its opened cases. For that page I've created an apex controller that queries for the account based on one of the account's fields.


Until now everything works fine, the query is a very simple one:


    List <Account> account =  [select  field1_c field2_c etc from Account where field1_c = :'ggggg'];

    List<Case> cases = [select  field1_c field2_c etc from Case where field1_c = :'ggggg'];


Now I would like to also have access to a relationship field and I would like to know how to query it.

The field I'm trying to show in that page is:




How should I write the select in order to query for this type of field?

They appear as default when I create a page with a standard controller referencing the account object.






Best Answer chosen by Admin (Salesforce Developers) 

[SELECT Parent.Parent.Account_Manager__r.FirstName FROM Account]