You need to sign in to do that
Don't have an account?
Peter 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;
}
}
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;
}
}