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
ArjunmcaArjunmca 

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.

Avidev9Avidev9

Observe the query

 

[SELECT  Name, productd__r.Name, (select Promotional_Price__c, Recurring_Price__c, Frequency_of_Charge__c from Recurring_Price__r) FROM Product_Options__c WHERE ProductD__C IN :lineItemProductMap.values()];

 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.

ArjunmcaArjunmca

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.

 

 

 

 

 

Avidev9Avidev9

Becasue you are not doing it properly

 

<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>

 

souvik9086souvik9086

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