代码分析

public with sharing class UpdateCurrencyIsoCode implements Triggers.Handler{     public void handle() {         if (Trigger.isUpdate) {             //当渠道预测币种更新时,销售渠道明细里的所有记录相应币种都要更新             List<Channel_Sales_Forecast__c> salesforecastNewUpdate =(List<Channel_Sales_Forecast__c>)Trigger.new;   
            Map<ID,String> currencyMap = new Map<ID,String>();
            Set<ID> parIdSet = new Set<ID>();             for(Channel_Sales_Forecast__c obj : salesforecastNewUpdate)             {                 //oldforecast                 Channel_Sales_Forecast__c oldforecast = (Channel_Sales_Forecast__c)Trigger.oldMap.get(obj.Id);                 if(obj.CurrencyIsoCode != oldforecast.CurrencyIsoCode)                 {                     parIdSet.add(obj.id);                     currencyMap.put(obj.id, obj.CurrencyIsoCode);                 }             }
            System.debug('asdfasdfsdfasdfsadf');
            List<Channel_Sales_Forecast_Details__c> csfDetail = new List<Channel_Sales_Forecast_Details__c>();                 //查询预测详情页上已有的记录             csfDetail = [select id,CurrencyIsoCode,Channel_Sales_Forecast__c,Channel_Sales_Forecast__r.CurrencyIsoCode from Channel_Sales_Forecast_Details__c                             where Channel_Sales_Forecast__c in :parIdSet];  //???//                          for(Channel_Sales_Forecast_Details__c  obj : csfDetail) {                 //                 //Channel_Sales_Forecast__c forecast = (Channel_Sales_Forecast__c)Trigger.oldMap.get(obj.Id);                 //if(obj.CurrencyIsoCode != salesforecastNewUpdate[0].CurrencyIsoCode) {   //如果header页货币种类发生了改变,那么相应的详情页列表中所有的记录都要改变                     obj.CurrencyIsoCode = currencyMap.get(obj.Channel_Sales_Forecast__c);                 //}             }             
            System.debug('csfDetail is = ' + csfDetail);
            update csfDetail;         }     } }
上一篇:C++拷贝构造函数,析构函数与内存泄漏的那些坑


下一篇:SAP CRM中间件Material Sales Organization和distribution channel的映射逻辑