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
salesVteamssalesVteams 

Fetching Data of multiple objects

Hi,

I have a problem while using relational query. I have Created tow objects one is master "Book" and other is "Details" which is child of "Book" object.

I am trying to fetch data from both objects by using relational query but its not getting compliled successfully. Please if any one could help me regarding this issue. Here is my query and error message given below:

Query : [select id, Name, Price__c,(SELECT Color FROM Details__r) FROM Book__c ];

 

Error:Error: Compile Error: Didn't understand relationship 'Details__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 20 column 18


Please guide me if someone can ...!

Thanks in Advance....

ibtesamibtesam

Go to the child object,

Go to the master detail relation and copy the "child relationship name"

and use that in the query with __r in the end.

 

Query : [select id, Name, Price__c,(SELECT Color FROM ChildRelationName__r ) FROM Book__c ];

Vinit_KumarVinit_Kumar

Hi ,

 

Your child relation ship name is not Details__r,please go to the relation ship field of your child object and look for relation ship name and replace Details__r with the relation ship name and you are good to go.

 

 

T.AizawaT.Aizawa

Book__c book = [select B.id, B.Name, B.Price__c, D.Color FROM Book__c B, Book__c.Details__r D];

 

:how to use

id-> book.id

Name-> book.Name

Price-> book.Price__c

Color-> book.Details__r.Color

 

I guess you get used to my funny English writing :D

salesVteamssalesVteams

Thanks a lot for your reply, i have sorted out the issue to some extent. I have created new child object "brels" of "Book".  Now here is the query which is getting compiled without any issue.

 

 oppz  =  [select a.id, a.Name, a.Price__c,(SELECT b.Bookcolor__c FROM a.brels__r b) FROM Book__c;

 

but now issue is that in view how to fetch child object field. I am using the code given below, but it works fine for master field but when i try to access children object  field "Bookcolor__c" it shows error, code and error is given below:

 

<apex:form >
<apex:pageBlockTable value="{!Oppz}" var="o">
        <apex:column >
        <apex:inputCheckbox value="{!o.id}"></apex:inputcheckbox>
        </apex:column>
        <apex:column value="{!o.Name}"/>
        <apex:column value="{!o.Price__c}"/>
        <apex:column value="{!o.Bookcolor__c}"/>
        <apex:column >
            <apex:outputLink value="{!$Page.edit_object}?id={!o.id}">Edit</apex:outputLink>           
       </apex:column>
        <apex:column >
            <apex:commandlink action="{!URLFOR($Action.Book__c.new,o.id)}" value="Edit">
             </apex:commandLink>         
       </apex:column>
    
       </apex:pageBlockTable>    
</apex:form>

 

ERROR : Error: Invalid field Bookcolor__c for SObject Book__c

 

So please let me know that how can i fetch children object field in view without any issue.

 

Thanks in advance.

ibtesamibtesam

o.Bookcolor__c is a list in itself, so collect it in a seperate list and access!

salesVteamssalesVteams

 

Can you please tell me how can i fetch that....

 

I am beginner so don't know how to do...

 

Thanks