I have one custom object which related to Account. one lookup field in Custom object which is to Account.
SELECT Id, Name, (SELECT id FROM Question_Answer__r) FROM Account
But this is showing don't understand relationship. Can anyone please help me
So you have a object, let se object1__c and it have a Account lookup (lets say Account__c).
In this scenario
Account - Parent Object1__c - Child
So your SOQL query should be like this
SELECT Id, Account__c, Account__r.Name, Account__r.Description FROM Object1__c
So if you want to query child object i.e
SELECT Id, Name, (SELECT Id, Name FROM Question_Answers__r) FROM Account
Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
for (Schema.ChildRelationship cr: R.getChildRelationships())
Try to run above describe call in developer console and check the debug log and check the correct relationship name for
Actually in your query you need to use Child-Relationship name of object.You can find this in the lookup of Account on Question_Answer__c object.For ex. On contact there is an lookup to account.On this you will see the child relationship name is contacts.
So if you query from account it would be like this:
Select Id, (Select id from Contacts) from Account
You can access the account from the custom object. In your case it is
You can write below query for this:
SELECT id, Account__c, Account__r.name from Question_Answer__c.
Note: Here Account__c is the api name of Account lookup, that you use in Custom object and Account__r denotes the relation name.
You can find out the relationship name, when you click on field mentioned in custom object. Below page is open.
Hope it helps you :)