+ Start a Discussion
prasanth puvvada 4prasanth puvvada 4 

soql subquery not coming in VF page.

i have written apex class (its working fine)  and VF page that is retriving the data from sub query, the error is coming at getting the data from subquery.  Error in VF:page is :-  

 Error: Invalid field loan__r for SObject customer__c

Visual force code:
 
<apex:page controller="solq3">
<apex:form>
<apex:pageblock>
<apex:pageblocktable title="customers and transactions" var="a" value="{!cuts}">
<apex:column value="{!a.id}" />
<apex:column value="{!a.Account_Type__c}" />
<apex:column value="{!a.City__c}" />
<apex:column value="{!a.Customer_name_del__c}" />


<apex:column>
<apex:repeat value="{!a.loan__r}" var="b">
{!b.Asset_cost__c} . {!b.Salary__c} <br/>

</apex:repeat>
</apex:column>


<!-- <apex:column value="{!a.Asset_cost__c}" />
<apex:column value="{!a.Salary__c}" /> -->


</apex:pageblocktable>
</apex:pageblock>
</apex:form>
</apex:page>

Apex code:
 
public class solq3
{
public list<customer__c> cuts{set;get;}
public list<account> accs{set;get;}


public solq3()
{
accs=[select id,name,industry,(select lastname,firstname,phone from contacts) from account];

cuts=[select id,Account_Type__c,City__c,Customer_name_del__c, (select Asset_cost__c,Salary__c,Applied_Date__c,Security__c from loans__r) from customer__c];


}
}


 
Best Answer chosen by prasanth puvvada 4
Amit Chaudhary 8Amit Chaudhary 8
You need to use "loans__r" not "loan__r"

Please try below code :-
 
<apex:page controller="solq3">
<apex:form>
<apex:pageblock>
<apex:pageblocktable title="customers and transactions" var="a" value="{!cuts}">
<apex:column value="{!a.id}" />
<apex:column value="{!a.Account_Type__c}" />
<apex:column value="{!a.City__c}" />
<apex:column value="{!a.Customer_name_del__c}" />


<apex:column>
<apex:repeat value="{!a.loans__r}" var="b">
{!b.Asset_cost__c} . {!b.Salary__c} <br/>

</apex:repeat>
</apex:column>


<!-- <apex:column value="{!a.Asset_cost__c}" />
<apex:column value="{!a.Salary__c}" /> -->


</apex:pageblocktable>
</apex:pageblock>
</apex:form>
</apex:page>


Please mark this as solution if this will help you

All Answers

Andy BoettcherAndy Boettcher
In your VF page - go view the relationship name in the Loan__c relationship field in the Customer__c object - use that in your SOQL and VF page.
Amit Chaudhary 8Amit Chaudhary 8
You need to use "loans__r" not "loan__r"

Please try below code :-
 
<apex:page controller="solq3">
<apex:form>
<apex:pageblock>
<apex:pageblocktable title="customers and transactions" var="a" value="{!cuts}">
<apex:column value="{!a.id}" />
<apex:column value="{!a.Account_Type__c}" />
<apex:column value="{!a.City__c}" />
<apex:column value="{!a.Customer_name_del__c}" />


<apex:column>
<apex:repeat value="{!a.loans__r}" var="b">
{!b.Asset_cost__c} . {!b.Salary__c} <br/>

</apex:repeat>
</apex:column>


<!-- <apex:column value="{!a.Asset_cost__c}" />
<apex:column value="{!a.Salary__c}" /> -->


</apex:pageblocktable>
</apex:pageblock>
</apex:form>
</apex:page>


Please mark this as solution if this will help you
This was selected as the best answer
prasanth puvvada 4prasanth puvvada 4
thankyou 
Amit Chaudhary............