【发布时间】:2011-09-08 20:49:07
【问题描述】:
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
当我尝试执行下面的代码时遇到上述错误。
我在机会的“之前”有一个触发器。然后它用 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 行并且代码运行,它会更新项目。我不明白为什么删除一个孩子的孩子(Opportunity -> OpportunityLineItem -> OpportunityLineItemSchedule)会导致递归循环。
我尝试在此链接中使用以下代码,但没有成功: http://boards.developerforce.com/t5/Apex-Code-Development/Trigger-is-fired-twice-due-to-the-workflow...
我还注释掉了所有其他触发器,以确保其中一个不会导致它。
有谁知道我做错了什么?
【问题讨论】:
标签: salesforce apex-code