0
votes

I have a custom Visualforce page that allows users to enter & modify Opportunity Product information.

I'm using an apex:pageblockTable to display a List that contains the line items related to an Opportunity. I would like to conditionally control the display behavior of certain fields based on the value of a related field in the related PRODUCT2 object, but I'm having problems.

This is my Visualforce code:

<apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Circuit__c.Label}">
<apex:inputField value="{!s.Circuit__c}" 
                 style="width:70px"
                 required="true" onkeyup="refreshTotals();"
                 rendered="{!s.Product2.ptype__c == 'Recurring'}"/>
</apex:column>

My intent is to conditionally render/not render the s.Circuit_c column/field based on what is in the 'ptype_c' field of the Product2 record that this OLI was originally populated from.

Although the code compiles without problem, when I execute it I'm getting the error "SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Product2"

Can someone help me understand the proper syntax for referencing a related object from inside of an Apex tag?

Thanks much.

1

1 Answers

1
votes

You VF syntax is correct but in query you missed quering Product2 field.

Query should look like this:

List<OpportunityLineItem> s =  [SELECT id, Circuit__c, Product2, Product2.ptype__c FROM OpportunityLineItem];

Check your query you are missing fields: Product2, Product2.ptype__c as it can be seen in exception also.