public class Opponent_Bid_InformationHandler extends Oly_TriggerHandler {
|
|
private Map<Id, Opponent_Bid_Information__c> newMap;
|
private Map<Id, Opponent_Bid_Information__c> oldMap;
|
private List<Opponent_Bid_Information__c> newList;
|
private List<Opponent_Bid_Information__c> oldList;
|
|
|
public Opponent_Bid_InformationHandler() {
|
this.newMap = (Map<Id, Opponent_Bid_Information__c>) Trigger.newMap;
|
this.oldMap = (Map<Id, Opponent_Bid_Information__c>) Trigger.oldMap;
|
this.newList = (List<Opponent_Bid_Information__c>) Trigger.new;
|
this.oldList = (List<Opponent_Bid_Information__c>) Trigger.old;
|
}
|
|
protected override void afterUpdate() {
|
// 更新询价的部分失单信息
|
updateOpponentInfo();
|
}
|
private void updateOpponentInfo() {
|
List<Opportunity> oppList = new List<Opportunity>();
|
// 因为没法跨表,所以进行select,如果使用那些字段,需要手动添加
|
List<Opponent_Bid_Information__c> temOBIList =
|
[select id,Opportunity__c,Report_Status__c,
|
Lost_By_Company__c,Lost_reason_main__c , of_lost_system_processor__c,
|
Lost_Reason_Sub__c, Lost_By_Product__c,
|
CompetitorProduct1__r.id, CompetitorProduct1__r.Name,
|
CompetitorProduct2__r.id, CompetitorProduct2__r.Name,
|
CompetitorProduct3__r.id, CompetitorProduct3__r.Name,
|
CompetitorProduct4__r.id, CompetitorProduct4__r.Name
|
from Opponent_Bid_Information__c
|
where id in: newList];
|
for (Opponent_Bid_Information__c n : temOBIList) {
|
if (n.Report_Status__c == '批准' ) {
|
Opportunity opp = new Opportunity();
|
opp.id = n.Opportunity__c;
|
|
opp.Lost_By_Company_part__c = n.Lost_By_Company__c;
|
opp.Lost_reason_main_part__c = n.Lost_reason_main__c;
|
opp.of_lost_system_processor_part__c = n.of_lost_system_processor__c;
|
if(n.Lost_Reason_Sub__c!=null){
|
opp.Lost_Reason_Sub_part__c = n.Lost_Reason_Sub__c+';';
|
}else{
|
opp.Lost_Reason_Sub_part__c = n.Lost_Reason_Sub__c;
|
}
|
opp.Lost_By_Product_part__c = n.Lost_By_Product__c;
|
|
if (n.CompetitorProduct1__r.id == '01t10000000Tqam') {
|
opp.CompetitorProduct1_part__c = n.Lost_By_Product__c;
|
} else {
|
opp.CompetitorProduct1_part__c = n.CompetitorProduct1__r.Name;
|
}
|
if (n.CompetitorProduct2__r.id == '01t10000000Tqam') {
|
opp.CompetitorProduct2_part__c = n.Lost_By_Product__c;
|
} else {
|
opp.CompetitorProduct2_part__c = n.CompetitorProduct2__r.Name;
|
}
|
if (n.CompetitorProduct3__r.id == '01t10000000Tqam') {
|
opp.CompetitorProduct3_part__c = n.Lost_By_Product__c;
|
} else {
|
opp.CompetitorProduct3_part__c = n.CompetitorProduct3__r.Name;
|
}
|
if (n.CompetitorProduct4__r.id == '01t10000000Tqam') {
|
opp.CompetitorProduct4_part__c = n.Lost_By_Product__c;
|
} else {
|
opp.CompetitorProduct4_part__c = n.CompetitorProduct4__r.Name;
|
}
|
oppList.add(opp);
|
}
|
}
|
if (oppList.size() > 0) update oppList;
|
}
|
|
}
|