Test Class Error:

System.DmlException: Upsert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (scheduling not enabled on product): [unknown]

I am not using "seeAllData" annotation. All solutions online are doing this.

Is there another workaround to assert OpportunityLineItemSchedule creation in a test class?

Product2[] products = new Product2[]
    new Product2(Name = 'ProductMedia1', IsActive = true, RecordTypeId = productRTMedia, Family = 'Media', Product_type__c = 'Ad Manager ads')
insert products;

// workaround to make Pricebooks to work in test class, without setting 'see All Data' to true
Pricebook2 pb = new Pricebook2(Id = Test.getStandardPricebookId(), IsActive = true);
update pb;

PricebookEntry[] pbes = new PricebookEntry[]
    new PricebookEntry(Pricebook2Id = pb.id, Product2Id = products[0].id, UnitPrice = 1, IsActive = true, UseStandardPrice = false)
insert pbes;
  • 1
    You need to check either QuantityScheduleType or RevenueScheduleType while inserting the Product, also you can a check in the trigger handler class so that the scheduling will not run for the product which doesn't have any of the schedules enabled. – rahul gawale Jan 31 at 17:37
  • @rahulgawale Thanks for the quick reply. If I put that check in the trigger handler class, then how will I assert Schedule creation in the test class? It will just be skipped. – Sidharth Agarwal Jan 31 at 17:42
  • that check is needed just to avoid running product schedules on the product which doesn't have scheduling enabled. To test the scheduling you need to check one of the checkboxes I have mentioned earlier. – rahul gawale Jan 31 at 17:48
  • I added the below to Prodct2 creation ``` RevenueScheduleType = 'Divide', RevenueInstallmentPeriod = 'Monthly', NumberOfRevenueInstallments = 10 ``` Getting this error now - Scheduling is not enabled for this type: [RevenueScheduleType] – Sidharth Agarwal Jan 31 at 17:50
  • 1
    @rahulgawale I had to set "CanUseRevenueSchedule" to TRUE in product setup along with other values. It's working now. Thanks so much for pointing me in the right direction. – Sidharth Agarwal Jan 31 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.