function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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 :{

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 : ) {
        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.




Thank you, I Have done it by using work flow thanks