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
Rachid El KaddouriRachid El Kaddouri 

apex class fetch data from related list from Custom Object


I'm stuck at this one. I'm trying to fetch fields from a related list but this ain't working for a custom object. This is my situation:
The Object Account has a related list that links to a child Custom Object named Account Locations. I want to fetch fields from this related list so I can show them in Google Maps as markers. This works for Contacts but for my custom object Account Locations this ain't working.
This is the controller:
public class AccountLocations {
    public Account AccountInformation {get; set;}

    public List<Account_Location__c> AllAccounts  {get; set;}
    public AccountLocations(ApexPages.StandardController controller) {

        AccountInformation = (Account)controller.getRecord();
    public void fetchtAllRelatedAccountLocations(){

    AllAccounts =
                SELECT Id, Location_Name__c, Location_Street__c, Location_Postal_Code__c, Location_City__c, Location_Country__c
                FROM Account_Location__c
                WHERE Id = :AccountInformation.Id

Hope someone has a solution or idea for this. 

Kind regards!
Jen BennettJen Bennett
I believe you want you WHERE clause to be something like where AccountId__c (depends on your relationship name) = :AccountInformation.Id.
Rachid El KaddouriRachid El Kaddouri
Thank you for the reply. When I want to save my visualforce page I get this error: Error: Unknown property 'AccountStandardController.Account_Location__c'

I want the page to show up in the Account Lay-Out therefore I need the standardcontroller in the vf page to be account and not account_location__c

Hope someone can help

Kind regards,
Ramanjaneya Reddy kalutlaRamanjaneya Reddy kalutla
I think for custom functonality we have to use controller not standardController. Just try with controller in apex page tag.
If it is wrong assumption please correct me when you get the answer.