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
Peter BittingerPeter Bittinger 

Trigger to Delete Line Item Schedules throws a SELF_REFERENCE_FROM_TRIGGER error

This trigger errors on the 'delete listofschedules' line.  The error is: 
SELF_REFERENCE_FROM_TRIGGER, Object (id = 00p650000038BBW) is currently in trigger OppLineItemDelSchedule, therefore it cannot recursively update itself: []: 

I think the issue is that updating the schedule records then updates the line item record which is already in the trigger.  Is there any way around this?

here is the code:
trigger OppLineItemDelSchedule on OpportunityLineItem (before update) {
Set<ID> oppItemIdsDel = new Set<ID>();
for (OpportunityLineItem itr : Trigger.New) {  
     if (itr.Delete_Schedule__c = TRUE) {                  
         if (itr.hasrevenueschedule) { oppItemIdsDel .add(itr.id); } 
         itr.Delete_Schedule__c = FALSE;                                                                                       
     }
}
     if (oppItemIdsDel.size() > 0) {
                list<opportunitylineitemschedule>  listofschedules = [select id from opportunitylineitemschedule where OpportunityLineItemId in :oppItemIdsDel  ];
        delete listofschedules;
     }
}