+ Start a Discussion
roni shoreroni shore 

Unable to fetch records

Hi Guys- I have an custom object "Address__c" related to Account, when passing the account id there I am not getting any records, please suggest

public with sharing class DisplayQueryList{ 
    public List<Address__c> Records {get; set;} 
    public DisplayQueryList(){ 
    Records = [select Id,Name FROM Address__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    system.debug('record-->'+Records); 
    } 
     
}
Best Answer chosen by roni shore
Om PrakashOm Prakash
Yes Roni, thats why I suggested to use the Api name of account lookup field in SOQL query above.
Please go to your Address Object details, view the field api name of account field there(As its custom field created by you).
Then use that api in where clause.
If you haven’t changed the api during field creation then it must Account__c but recheck and update your code.

All Answers

Raj VakatiRaj Vakati
public with sharing class DisplayQueryList{ 
    public List<Address__c> Records {get; set;} 
    public DisplayQueryList(){ 
    Records = [select Id,Name FROM Address__c WHERE Account__c = :ApexPages.currentPage().getParameters().get('id')];
    system.debug('record-->'+Records); 
    } 
     
}
roni shoreroni shore
hi Raj- Account is std object here, even though I pass AccountId=:ApexPages.currentPage().getParameters().get('id') 
or
Account__c = :ApexPages.currentPage().getParameters().get('id')]
it doesnt save.
Om PrakashOm Prakash
Hi Roni,
In where clause of SOQL, use the API name of account  lookup field instead of id.
If you know the id of Address record then only your existing code will fetch the records from address object.
roni shoreroni shore
The page is on Account object so whenever an related Address record is created, based on the Account id I need to display the address on the page
Om PrakashOm Prakash
Yes Roni, thats why I suggested to use the Api name of account lookup field in SOQL query above.
Please go to your Address Object details, view the field api name of account field there(As its custom field created by you).
Then use that api in where clause.
If you haven’t changed the api during field creation then it must Account__c but recheck and update your code.
This was selected as the best answer