We are using the custom product scheduling in our organization.

When I am deleting the existing schedules its also updating the OpprtunityLineitem's quanity, salesprice and unitprice to '0'. Where as in standard schedule if we delete the schedule it will not update the above fields.

I don't t want to update the OpportunityLineItem fields on deleting the schedule.

I am using the below query in my class:

Delete [SELECT id from OpportunityLineItemSchedule where OpportunityLineItemId = :oli.id ];

how to fix it?

  • 2
    salesforce.com/us/developer/docs/api/Content/… "Deleting an OpportunityLineItemSchedule decrements the OpportunityLineItem TotalPrice by the deleted OpportunityLineItemSchedule Quantity or Revenue amount. The Opportunity Amount is also decremented by the OpportunityLineItemSchedule Quantity or Revenue amount, and the Opportunity ExpectedRevenue is reduced by OpportunityLineItemSchedule Quantity or Revenue amount multiplied by the Opportunity Probability." Oct 23, 2012 at 9:40
  • 1
    yes, but in my case even the quantity is also getting updated to 0,which wont happen in standard delete of the schedule. Oct 23, 2012 at 10:38

2 Answers 2


You can restore the data after the deletion, like so:

delete [SELECT Id FROM OpportunityLineItemSchedule WHERE OpportunityLineItemId = :oli.id];
update oli;

I've come across something similar previously - Salesforce - Unable to set OpportunityLineItem Quantity or TotalPrice when using Revenue Schedule.

In that case I had to retrieve the OpportunityLineItem record after deleting the associated OpportunityLineItemSchedule records before the Quantity could be updated.

OpportunityLineItem oli = [Select Id, UnitPrice, TotalPrice, Quantity   
    from OpportunityLineItem where Id = '00k4000000MXyoHAAT']; // Your OLI id here
OpportunityLineItemSchedule olis = [Select Id 
    from OpportunityLineItemSchedule where OpportunityLineItemId = :oli.Id];

Savepoint sp = Database.setSavepoint();

delete olis;

// If the OLI isn't reloaded from the DB after deleting the OpportunityLineItemSchedule 
// records you will get the DmlException about changing both the UnitPrice and the TotalPrice
// due to the changes the deletion causes
oli = [Select Id, UnitPrice, TotalPrice, Quantity 
    from OpportunityLineItem where Id = '00k4000000MXyoHAAT'];

oli.Quantity = oli.Quantity + 10;
oli.TotalPrice = oli.UnitPrice * oli.Quantity;
update oli;


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .