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
SebasSebas 

FIELD_INTEGRITY_EXCEPTION (total price must be specified)

Hello!

I'm having an issue while updating 2 or more OpportunityLineItems. Salesforce gives me the following error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: TotalPrice (total price must be specified): [TotalPrice]

 

And It's the wrong error.

 

The thing is that OpportunityLineItem has a cutom Text field named "testo", with the option "Do not allow duplicate values" checked, and before updating I set both line items with the same value in this text field. And unitPrice and totalPrice are not empty, for sure

 

If I uncheck the option to allow duplicate values, the error gets fixed!

 

Here I paste an Apex Test Class to reproduce this error. Just create a new Text field called testo and run the test.

I've tested this in a production enviroment and in my developer account.

 

Let me know if this is a bug or if i'm wrong

Thanks!

Regards

Sebastian

 

 

public class Test {

    @isTest
    static void myUnitTest() {
        Account a = new Account(name='client x');
        insert a;
       
        Opportunity o = new Opportunity(
            name = 'test',
            closeDate = system.today(),
            accountid = a.id,
            stageName='Close/Won'
        );
        insert o;
       
        Product2 p = new Product2(Name = 'Issue');
        insert p;
       
        Pricebook2 pb = [select Id from Pricebook2 where IsStandard = true];
        PricebookEntry pbe = new PricebookEntry(Pricebook2Id=pb.id,Product2Id=p.id, UnitPrice=15, IsActive=TRUE, UseStandardPrice=false);
        insert pbe;
       
        OpportunityLineItem li1 = new OpportunityLineItem(
            opportunityId = o.id,
            pricebookEntryId = pbe.id,
            quantity = 1,
            unitPrice = 10
        );
        insert li1;
        OpportunityLineItem li2 = new OpportunityLineItem(
            opportunityId = o.id,
            pricebookEntryId = pbe.id,
            quantity = 1,
            unitPrice = 10
        );
        insert li2;
       
        system.assertNotEquals(null, li1.unitPrice);
        system.assertNotEquals(null, [select totalPrice from opportunityLineItem where id = :li1.id].totalPrice);
        system.assertNotEquals(null, li2.unitPrice);
        system.assertNotEquals(null, [select totalPrice from opportunityLineItem where id = :li2.id].totalPrice);
       
        li1.testo__c = '1234';
        li2.testo__c = '1234';
       
        update new OpportunityLineItem[]{ li1, li2 };
    }
}

Bruce PVN Van BurenBruce PVN Van Buren
Its a bug