+ Start a Discussion

Invalid field TotalPrice for SObject Opportunity

public class ACommissionController {

    public PageReference genMyList() {
        MyList = bMyList();
        return null;
     /* New wrapper class */
    public class cOpportunity{
        public Opportunity myopp {get; set;}
        Double Subtotal = 0;
        /*This is the constructor method. When we create a new cOpportunity object. We also set the Subtotal value to zero*/
        public cOpportunity(Opportunity o){
            myopp = o;
           Subtotal = Subtotal + o.TotalPrice;
        public Double Getsubtotal() {
            return Subtotal;
            //return null;

    //A collection of the class/wrapper objects cOpportunity
    public List<cOpportunity> MyList {get; set;}
    //This method uses a SOQL query to return a List of Opportunities
    public List<cOpportunity> bMyList(){
        ID id = '0068000000NyTHe'; // Used for testing purposes right now.

          if(MyList == null){
            MyList = new List<cOpportunity>();
             for(Opportunity opp : [SELECT o.Id, o.Name, o.Amount, (SELECT op.Quantity, op.UnitPrice, op.TotalPrice,
                   op.PricebookEntry.Name, op.OpportunityId,
                   FROM OpportunityLineItems op)
                   FROM Opportunity o where Id = :id]){
                /* As each opportunity is processed I create a new cOpportunity object and add it to MyList */
                MyList.add(new cOpportunity(opp));
        return MyList;


I'm trying to create a quote that will be separated by productFamily, I'll take care of that when I get there.  Right now, I'm trying to add together each TotalPrice to get a subtotal but I'm receiving the following error.


Invalid field TotalPrice for SObject Opportunity.


So how do I access a child element in this query?  Thanks for any help you can provide.