【发布时间】:2017-12-07 02:14:03
【问题描述】:
我的情况:- 我有两个自定义对象 order-master 和 Sellar- 产品在order-master上有查找关系。当我选择卖方时- 产品我需要在 order-master 中填充其 mrp__c、Selling_price_cc。 我为此编写了一个触发器(工作)并在保存后获取值 卖方主记录,但在提交记录之前我需要值。
trigger AutoPopulate on Order_Master__c (before insert, before update) {
Set <ID> SetSpIds = new Set<ID>();
for(Order_Master__c om : trigger.new){
if(om.SellerProductId__c != null){
SetSpIds.add(om.SellerProductId__c);
}
}
MAP<ID, Sellar_Products__c> mapSp = new MAP<ID, Sellar_Products__c>
([select MRP__c, Offer_Rate__c, Selling_Price__c from Sellar_Products__c
where id in:SetSpIds]);
for(Order_Master__c om : trigger.new){
if(om.SellerProductId__c != null){
Sellar_Products__c Sp = mapSp.get(om.SellerProductId__c);
om.Item_Price__c = Sp.MRP__c;
om.Discount__c = Sp.Offer_Rate__c;
om.Total_cost__c = Sp.Selling_Price__c;
}
}
}
【问题讨论】:
标签: triggers salesforce apex-code apex