Skip to main content
Hi,

I have a query of the OpportunityLineItem object that is being run based on the account id.  Basically, I want to sum up all the totals for differnt products and display them in a chart.  This is working, except for the name of the product being displayed is the opportunity name AND the product name.  This means that duplicate products on different opportunities are not being summed like they should.

Any ideas?

Thanks,
3 answers
  1. Feb 7, 2015, 5:06 PM

    So my original code is 

    List<OpportunityLineItem> getList= [SELECT Id, Name, TotalPrice FROM OpportunityLineItem

    WHERE Opportunity.AccountId=:ApexPages.currentPage().getParameters().get('id')

    ORDER BY Name];

    Which works except for the combing of the opportunity name with the product name. When I try using Product2.name

     

    List<OpportunityLineItem> getList= [SELECT Id, Product2.Name, TotalPrice FROM OpportunityLineItem

    WHERE Opportunity.AccountId=:ApexPages.currentPage().getParameters().get('id')

    ORDER BY Name];

    I get the following error on my visual force page  "

    System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Name 

    Class.AccountChartClass.getChart1: line 11, column 1"

    I'm not sure what I'm doing wrong

    Thanks,

     
0/9000