my case :- i have two custom objects order-master and Sellar- Products have look-up relation on order-master. when i select sellar- product i need to populate its mrp__c, Selling_price_cc in order-master. i have written a trigger for this(working) and getting values after save the sellar-master record but i need values before submit record.
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;
}
}
}