2013-12-12 19 views
1

我在帳戶對象上有一個字段,它在編輯帳戶時進行更新。當單獨編輯記錄時,將正確的值寫入該字段。當我使用數據加載器。 。 。一個值適用於所有記錄。這是我的觸發器,請告知。Apex觸發器 - 使用數據加載器時的值不正確

trigger Populate_Transfer_Manager on Account (before insert, before Update) { 

    list<id> aid = new list<id>(); 
    for(account a: trigger.new){   
     aid.add(a.ownerid); 
    } 

list<user> managers = new list<user>(); 
    managers = [select managerid from user where id in: aid]; 


set<id> manid = new set<id>();        
    for(user u: managers){ 
     manid.add(u.managerid); 
    } 


for(account a: trigger.new){   
    for(id i: manid){   
      a.transfer_manager__c = i;  
     } 
    } 
} 
+1

我想出了使用地圖。我無法將解決方案再發布8個小時。今天晚些時候會發布。 – Berg

+0

心還在更新,以便其他人可以從你的錯誤中學習? –

回答

0

該觸發器僅對每批次的200次觸發一次,並將該值分配給該批次中的所有記錄。使用地圖我能夠將正確的值分配給我的數據庫中的所有記錄。

trigger Populate_Transfer_Manager on Account (before insert, before Update) {  

    list<id> aid = new list<id>(); 
    for(account a: trigger.new){     
     aid.add(a.ownerid); 
      } 
    map<id, user> users = new map<id, user>(
     [select managerid from user where id in: aid]); 

    for(account a: trigger.new){ 
     a.Transfer_Manager__c = users.get(a.ownerid).managerid; 
    } 
} 
相關問題