Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger triggerOpportunityCloseInstallDateChange caused an unexpected exception, contact your administrator: triggerOpportunityCloseInstallDateChange: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00o30000003ySNhAAM; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0063000000i23T9) is currently in trigger triggerOpportunityCloseInstallDateChange, therefore it cannot recursively update itself: []: Class.OpportunitySchedule.BuildScheduleAndUpdateDates: line 17, column 5
Я получаю вышеуказанную ошибку, когда пытаюсь извинить приведенный ниже код.Это мой второй день на земле APEX, так что со мной все в порядке.
У меня есть триггер на «до» возможности.Затем он вызывает приведенный ниже класс с помощью trigger.new.
public with sharing class OpportunitySchedule {
public static void BuildScheduleAndUpdateDates(List<Opportunity> OpportunityList) {
for (Integer i = 0; i < OpportunityList.size(); i++)
{
Opportunity opp_new = OpportunityList[i];
List<OpportunityLineItem> lineItems = [Select o.Id, (Select OpportunityLineItemId From OpportunityLineItemSchedules), o.System_Add_on__c, o.ServiceDate, o.Schedule_Length__c , o.Monthly_Quantity__c, o.Monthly_Amount__c
From OpportunityLineItem o
where o.Opportunity.Id = :opp_new.Id];
for (OpportunityLineItem item : lineItems)
{
item.ServiceDate = opp_new.CloseDate;
update item;
delete item.OpportunityLineItemSchedules;
}
}
}
}
Я пытаюсь удалить все расписания позиций, когда кто-то редактирует возможность.Странно то, что я могу удалить элемент delete.OpportunityLineItemSchedules и код запускается, он обновит элемент.Я не понимаю, почему удаление потомков childs (Opportunity -> OpportunityLineItem -> OpportunityLineItemSchedule) приведет к рекурсивному циклу.
Я попытался выполнить приведенный ниже код в этой ссылке, но не повезло:1010 *
Я также закомментировал все остальные триггеры, чтобы убедиться, что один из них не вызывает его.
Кто-нибудь знает, что я делаю не так?