• DSchuller
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I am working with a client that wants to produce a quote that lists all OpportunityLineItems sub-divided by Product Family. So Family A all grouped together with a subtotal and then Family B and so on.  Then when all items are outputted, to give the grand total.
I've modified some of the sample code and can get the basic output.  It will list all OpportunityLineItems but I now need to be able to separate by product family and add in a subtotal.

public class mySecondController {
    public Opportunity getOpportunity() {
        //Manually entering ID for testing purposes
        ID id = '0068000000NyTHe';
        return [SELECT Id, Name, (SELECT Quantity, UnitPrice, TotalPrice,
                    PricebookEntry.Name,
                    PricebookEntry.Product2.Family
                    FROM OpportunityLineItems) FROM Opportunity where Id = :id];
                    // where id = :ApexPage.currentPageReference().getParameters().get('id')];
    }

    public String getName() {
        return 'My Second Custom Controller';
    }
}

<apex:page controller="mySecondController" tabStyle="Opportunity" showHeader="false" renderas="pdf">
    Opportunity: {!Opportunity.Name}
    <br/>
    Id: {!Opportunity.Id}
    <br/>
        
    <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
      <p>Name: {!line.PricebookEntry.Name}<br/>
      Family: {!line.PricebookEntry.Product2.Family}</p>
    </apex:repeat>  
    
</apex:page>