You need to sign in to do that
Don't have an account?

Help needed on Trigger
Hi Team,
I am using below trigger to update price filed from Product Shipper to DsP Product. It is working fine for new records but if change the price in product shipper then the value is updating but total amount is not getting exactly. this price field is using in workflow to calcuate the total amount.
trigger UpdatePrice on DSP_Product__c (before insert, before update) {
set<String> years = new set<String>();
set<Id> accounts = new set<Id>();
map<String, Id> prevYearKeyDspMap = new map<String, Id>();
for(DSP_Product__c dspr : trigger.new){
accounts.add(dspr.Account__c);
years.add(dspr.Name);
}
Map<ID, Product_Shipper__c> psMap =
new Map<ID, Product_Shipper__c>(
[SELECT Price__c, Pack_Size__c
FROM Product_Shipper__c
WHERE Active__c = true]);
for ( DSP_Product__c dspp : trigger.new ) {
if (prevYearKeyDspMap.size()>0){
Product_Shipper__c ps = psMap.get(dspp.Product_Shipper__c);
if ( ps != null ) {
dspp.Product_Price__c = ps.Price__c;
dspp.Product_Size__c = ps.Pack_Size__c;
}
}
}
}
Your "if (prevYearKeyDspMap.size()>0)" will never be true because you never put anything in that map, so I'd figure out what you want to do with that first.
Hi,
Thank you, I Have done it by using work flow thanks