2012-02-23 96 views
1
Log.add(new Cx_Trans_Log__c(
       Object__c = 'Activity', 
       Object_Id__c = newActivity.Name, 
       Owner2_Id__c = newActivity.Owner1_Id__c, 

我正在使用上面的代碼在salesforce.com中更改某個活動時創建新的日誌記錄。從newActivity.Owner1_Id__c創建的Owner2_Id__c不會給我Owner1_Id__c的名稱(這是查找(用戶)字段)。有沒有辦法讓Owner1到Owner2中顯示的用戶名?創建新記錄的頂點觸發器創建號碼

+0

你新owner2的名字在觸發,或者你只是需要它來顯示跨日誌詳細信息頁上? – 2012-02-23 21:44:43

回答

5

正確的做法是做一個查詢。在這個例子中,我將通過活動,假設你的意思任務:

Set<Id> userIds = new Set<Id>(); 
for (Task t : Trigger.new) { 
    userIds.add(t.OwnerId); 
} 
Map<Id, User> users = new Map<Id, User>([SELECT Name FROM User WHERE Id IN :userIds]); 

// then you could plug something like this into your existing code 
String userName = users.get(newActivity.Onwer1_Id__c).Name; 
+0

在這種情況下,選擇到地圖中特別有用。 – Adam 2012-02-24 18:07:05