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

Create opportunityLineItemSchedule using apex ?


I want to creat opportunityLineItemSchedule in my test class and I'm not getting the way... my code is....

Product2 objproductQS = new Product2(); ='testproduct1';
objproductQS.IsActive = true;
objproductQS.CanUseQuantitySchedule = true;
objproductQS.QuantityInstallmentPeriod = 'weekly';
objproductQS.QuantityScheduleType = 'Divide';
objproductQS.NumberOfQuantityInstallments = 52;
insert objproductQS;

List<Pricebook2> pid=[Select Id From Pricebook2 where name = 'Standard Price Book'];
String stdPbId = pid[0].Id;

PricebookEntry objpricebookEntryQS = new PricebookEntry();
objpricebookEntryQS.Pricebook2Id = stdPbId;
objpricebookEntryQS.Product2Id =;
objpricebookEntryQS.UnitPrice = Decimal.valueof(33333);
objpricebookEntryQS.IsActive = true;
insert objpricebookEntryQS;

opportunityLineItemSchedule ols = new opportunityLineItemSchedule();
ols.ScheduleDate =;
ols.opportunityLineItemID =;
ols.type = 'quantity';
insert ols;

giving me this error..... System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: Type,
Quantity, unknown (invalid quantity/revenue for given type): [Type, Quantity, unknown]

so anyone knows about it's any fix .. than plz let me know..... thanks ............. :)

The Quantity and Revenue fields have the following restrictions when this object is updated, please check your code for these:

>For a schedule of TypeQuantity, you can’t update a null Revenue value to non-null. Likewise for a schedule of TypeRevenue, you can’t update a null Quantity value to non-null.

>You can’t null out the Quantity field for a schedule of TypeQuantity. Likewise you can’t null out the Revenue field for a schedule of TypeRevenue.

>You can’t null out either the Revenue or Quantity fields for a schedule of type Both.