You need to sign in to do that
Don't have an account?

outputField can only be used with SObject fields
Hi,
I am getting error as ' outputField can only be used with SObject fields'
at ' lnitems.Recurring_Price__r.Recurring_Price__c'
Controller
--------------
public
withsharingclass TestController
{
public List<Product_Options__c> getSPCartLineItems()
{
List<
Shopping_Cart_Line_Item__c> splnitem = [select product__C, quantity__c fromShopping_Cart_Line_Item__c];
Map<Id, Id> lineItemProductMap =
new Map<Id, Id>();
//Map<Id, Id> lineItemProductMap = new Map<Id, Id>();
for (Shopping_Cart_Line_Item__c item : splnitem)
{
lineItemProductMap.put(item.Id, item.product__c);
}
List<
Product_Options__c> productOptionsList = [SELECT Name, productd__r.Name, (select Promotional_Price__c, Recurring_Price__c, Frequency_of_Charge__c from Recurring_Price__r) FROMProduct_Options__cWHERE ProductD__C IN :lineItemProductMap.values()];
System.debug(
'Test: productOptionsList=' + productOptionsList);
if (!productOptionsList.isEmpty())
{
System.debug(
'Test: Option Name=' + productOptionsList[0].Productd__r.Name);
System.debug(
'Test: recurring price=' + productOptionsList[0].Recurring_Price__r[0].Recurring_Price__c);
}
return productOptionsList;
}
VisualForce
--------------------
<apex:pageblock >
<apex:pageblocktable value="{!SPCartLineItems}" var="lnitems">
<apex:column headerValue="Products">
<apex:outputfield value="{!lnitems.Productd__r.Name}"/>
</apex:column>
<apex:column headerValue="Price">
<apex:outputfield value="{!lnitems.Recurring_Price__r.Recurring_Price__c}"/> </apex:column>
</apex:pageblocktable>
</apex:pageblock>
}
Can any body please fix this issue.
Thanks.
Observe the query
The highlighted portion is nested query and brings in child records. So each parent record i.e Product_Options__c can have multiple child records and hence lnitems.Recurring_Price__r is a List. You cannot access list by doing "lnitems.Recurring_Price__r.Recurring_Price__c". you have to do a repeat over lnitems.Recurring_Price__r.
Hi,
I have tried looping thorugh lnitems.Recurring_Price__r.
But value is not displaying rec.Recurring_Price__r.Recurring_Price__c
<apex:pageblock >
<apex:pageblocktable value="{!SPCartLineItems}" var="lnitems">
<apex:column headerValue="Products">
<apex:outputfield value="{!lnitems.Productd__r.Name}"/>
</apex:column>
<apex:pageblocktable value="{!lnitems.Recurring_Price__r}" var="rec">
<apex:column headerValue="Price">
<apex:outputfield value="{!rec.Recurring_Price__r.Recurring_Price__c}"/>
</apex:column>
</apex:pageblocktable>
</apex:pageblocktable>
</apex:pageblock>
Should i put rec.Recurring_Price__r[0].Recurring_Price__c?
Regards,
Arjun.
Becasue you are not doing it properly
Hi, you are accessing this twice
Change the blue colored text.
<apex:pageblock >
<apex:pageblocktable value="{!SPCartLineItems}" var="lnitems">
<apex:column headerValue="Products">
<apex:outputfield value="{!lnitems.Productd__r.Name}"/>
</apex:column>
<apex:pageblocktable value="{!lnitems.Recurring_Price__r}" var="rec">
<apex:column headerValue="Price">
<apex:outputfield value="{!rec.Recurring_Price__c}"/>
</apex:column>
</apex:pageblocktable>
</apex:pageblocktable>
</apex:pageblock>
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks