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
etechcareersetechcareers 

Constructor not defined: [ProductBreakdown.OpportunityTotal]???

Hi I keep getting this error:

Constructor not defined: [ProductBreakdown.OpportunityTotal].<Constructor>(SOBJECT:OpportunityLineItem)

What is wrong with my code?

 

   public List<OpportunityTotal> getOpportunityTotals() {
        List<OpportunityTotal> OpportunityTotals = new List<OpportunityTotal>();
        for(OpportunityLineItem o:[SELECT Id,  
                            TotalPrice, Product_Name__c, Opportunity.Id, 
                            Opportunity.Name, Opportunity.StageName,
                            Opportunity.Accountid, Opportunity.Amount 
                            FROM OpportunityLineItem Where 
                            Opportunity.StageName='Closed Won' And 
                            Opportunity.Account.id='001Q000000Js7pP' 
                            ])
            {
                OpportunityTotals.add(new OpportunityTotal(o));
            }
        return sortOpportunityTotals(OpportunityTotals);
    }

 Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
ministe2003ministe2003

The error is at this line:

 

OpportunityTotals.add(new OpportunityTotal(o));

You're creating a new OpportyunityTotal object and passing an OpportunityLineItem into it's constructor.  Now, I dont know what OpportyunityTotals is, I'm guessing its the name of a custom object you've created which has a field of OpportunityLineItem type.  If I'm right, you need to pass the name of the field when you construct the object.

 

Lets say your OpportunityLineItem field name on the OpportyunityTotal object is called OLI.  You would construct like:

 

OpportunityTotals.add(new OpportunityTotal(OLI = o));