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
deux4everdeux4ever 

SOQL and Opportunity Line Items

What is the correct SOQL statement to access Opportunity Line Items (Products) from an Opportunity?
@anilbathula@@anilbathula@
Hi deux4ever,

Are you trying to get opportunity line items in opportunity as inner query.
Then try this query

Select Amount,CloseDate,Name, (Select PricebookEntry.Product2Id, TotalPrice, UnitPrice, ListPrice From OpportunityLineItems) From Opportunity

Thanks
Anil.B
deux4everdeux4ever
Thanks! That helped a lot. How would I access the inner soql statement from Visualforce? I can access the outer by calling the query from my custom controller, but when I try to do something like {!Opp.UnitPrice}, I get an error stating "Could not resolve field 'UnitPrice'..."
@anilbathula@@anilbathula@
Hi deux4ever,

If you want to dispaly them in viusal force page 
try these code:
<apex:pageBlockTable value="{!opp.OpportunityLineitems}" var="ol" id="lineitems">
 <apex:column headerValue="Total Price" value="{!ol.totalprice}"/> 
<apex:column headerValue="unitprice" value="{!ol.unitprice}"/>
 </apex:pageBlockTable>

Thanks
Anil.B
 
deux4everdeux4ever
This is not working for me. Even when I tried to put this inside my original pageBlockTable, a table does not populate in my visualforce page.