You need to sign in to do that
Don't have an account?
Invalid foreign key relationship
Hi,
I am trying to fetch child object field but its showing error "Invalid foreign key relationship: Book__c.brels__r" to me. Code i am using to fetch the filed is given below:
updatebook = [select a.id, a.Name, a.Price__c,(SELECT b.Bookcolor__c FROM a.brels__r b) FROM Book__c a where id = :ApexPages.currentPage().getParameters().get('id')];//[select id, Name, Price__c from Book__C where id = :ApexPages.currentPage().getParameters().get('id')];
name = updatebook.Name;
price = updatebook.Price__c;
color = updatebook.brels__r.Bookcolor__c;
Please help me if some one can do. Waiting for your eply.
Thanks
Try using the plural label of the object with __r. For eg. If the object name is Sale, and the plural label is Sales, use Sales__r
Thanks
Hi,
Thanks for reply, but i have already used plural one like "color = updatebook.brels__r.Bookcolor__c;"
but its not working.
Instead of a nested SELECT, how about just returning the related object in the SOQL.
Hi ,
Can you make the following change in your SOQL and see if that works :-
from
[select a.id, a.Name, a.Price__c,(SELECT b.Bookcolor__c FROM a.brels__r b) FROM Book__c a where id = :ApexPages.currentPage().getParameters().get('id')];
to
[select id, Name, Price__c,(SELECT Bookcolor__c FROM brels__r ) FROM Book__c where id = :ApexPages.currentPage().getParameters().get('id')];