我想知道是否有人可以帮助我修改此触发器。我遇到问题 机会在关闭/赢得后正在更新,这会用代表的当前经理覆盖旧的(正确的经理)。这是一个问题,因为我有一个创建 Actuals 的触发器,它正在编辑 Actuals 并将它们写入当前 Manager 而不是旧 Manager。我真的很困惑最好的编辑位置在哪里,如果在触发器旧地图中 StageName 是 Closed/Won 并且 StageName 目前等于 Closed/Won,则在 if 语句放置和 ifelse 语句开始之后的底部,然后不要'不更新当前实际值。这是触发器:
trigger CreateActualsAndTargets on Opportunity (after insert, after update)
{
if(Trigger.isUpdate || Trigger.isInsert)
{
Map<ID,Opportunity> l_OpportunityOwners = new Map<ID,Opportunity> ([Select id,o.Owner.ManagerId,Contract_ID__c,StageName,Amount,AccountId,CloseDate, o.OwnerId, Type From Opportunity o where id in:trigger.newMap.keySet()]);
GooalAndActuals l_oGooalAndActuals = new GooalAndActuals ();
for(Opportunity l_oOpportunityNew:l_OpportunityOwners.values())
{
System.debug('********************Trigger Start***********************');
if(l_oOpportunityNew.StageName=='Closed/Won')
{
ID SalesRepGoalID,ManagerGoalID;
//modified
l_oGooalAndActuals = new GooalAndActuals ();
l_oGooalAndActuals.opportunityNew=l_oOpportunityNew;
//Goal Creation
SalesRepGoalID=l_oGooalAndActuals.CreateGoal(l_oOpportunityNew.OwnerId);//SalesRep Goal Creation
if(l_oOpportunityNew.Owner.ManagerId!= null)
{
ManagerGoalID=l_oGooalAndActuals.CreateGoal(l_oOpportunityNew.Owner.ManagerId);//Manager Goal Creation
}
//Actual Deletion
if(Trigger.isUpdate)
{
l_oGooalAndActuals.DeleteActual(l_oOpportunityNew.Id);
}
//Actual Creation
l_oGooalAndActuals.CreateActual(l_oOpportunityNew.OwnerId,SalesRepGoalID);//SalesRep Actual Creation
if(l_oOpportunityNew.Owner.ManagerId!= null)
{
l_oGooalAndActuals.CreateActual(l_oOpportunityNew.Owner.ManagerId,ManagerGoalID);//Manager Actual Creation
}
}
/*
Start: Project
* Author |Author-Email |Date |Comment
* ----------------|------------------------|-----------|--------------------------------------------------
* Sakonent Admin |abrar.haq@sakonent.com |02.16.2012 |Initial code
* Purpose: It will remove Actual record(s) associated to Opportunity if Stage goes from 'Closed/Won' to some other stage.
*/
else if(Trigger.isUpdate)
{
if(Trigger.oldMap.get(l_oOpportunityNew.Id).StageName == 'Closed/Won' && l_oOpportunityNew.StageName != 'Closed/Won')
{
l_oGooalAndActuals = new GooalAndActuals ();
l_oGooalAndActuals.opportunityNew=l_oOpportunityNew;
l_oGooalAndActuals.DeleteActual(l_oOpportunityNew.Id);
}
}
/*End: Project */
}
}
}