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
ALAL 

FIELD_INTEGRITY_EXCEPTION, field integrity exception: TotalPrice (total price must be specified): [TotalPrice]

Hello,

I am attempting to run an apex test class to deploy the changes to our production org. I would like to setup a test to insert an opportunity as well as the opportunity products. I get the error below that the TotalPrice field is required even though I've included it in my code. Are there any other fields that I am missing? 

Thank you for your help

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: TotalPrice (total price must be specified): [TotalPrice]
  Opportunity o = new Opportunity(Name = 'Test Opportunity', AccountId = a.Id, CloseDate = Date.today(), StageName = 'Prospecting', Maintenance_Type__c = 'Standard Maintenance', Competitors__c = 'Test' );
        if (isSandbox) 
        o.Pricebook2Id = defaultPB.Id;
        insert(o);

    List<OpportunityLineItem> items = new List<OpportunityLineItem>();
        for (PricebookEntry pbe: products)
        {
            OpportunityLineItem temp = new OpportunityLineItem();
            temp.OpportunityId = o.Id;
            temp.PricebookEntryId = pbe.Id;
            temp.Quantity = 3;
            
            //temp.UnitPrice = 100;
            temp.TotalPrice = 0; 
           
            items.add(temp);
      
        }