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的第二天,和我一起裸露在外。Salesforce Apex錯誤:SELF_REFERENCE_FROM_TRIGGER
我在機會的「之前」有一個觸發器。然後用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;
}
}
}
}
我試圖在有人編輯機會時刪除所有機會行項目計劃。奇怪的是,我可以刪除刪除item.OpportunityLineItemSchedules行和代碼運行,它會更新該項目。我不明白爲什麼刪除孩子的孩子(機會 - > OpportunityLineItem - > OpportunityLineItemSchedule)會導致遞歸循環。
我試圖在這個環節上沒有運氣implimenting下面的代碼: http://boards.developerforce.com/t5/Apex-Code-Development/Trigger-is-fired-twice-due-to-the-workflow ...
我還評論了其他所有的觸發器,以確保他們的一個不導致它。
有誰知道我在做什麼錯?
大家好我有同樣的problem.Can請您點擊此鏈接http://salesforce.stackexchange.com/questions/43871/system-dmlexception-delete-failed-self-reference-from-trigger見記錄我有一個相同的問題。 – Prathyush