Find your content:

Search form

You are here

OpportunityLineItemschedule deletion problem?

 
Share

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?


Attribution to: Keepcalmncode

Possible Suggestion/Solution #1

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;

Database.rollback(sp);

Attribution to: Daniel Ballinger

Possible Suggestion/Solution #2

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

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

Attribution to: sfdcfox
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3611

My Block Status

My Block Content