2012-08-31 16 views
0

我有自定義對象KeywordAccountAssociation__c。這個對象有三個字段更新自定義對象的多選項列表

  1. Account__c - 主 - (賬戶)
  2. Keyword__c - 主 - (關鍵字)
  3. Compositecp__c - 文本(255)(外部ID)(唯一區分大小寫)

我有帳戶的自定義字段

  • DD_Segment__c - 多選擇列表

現在我想只要KeywordAccountAssociation__c更新來更新(插入是罰款太)值DD_Segment__c。我可以寫這個觸發器,但我不知道如何?我是Salesforce Development的新手,我的背景是ruby(所以習慣apex對我來說有點困難)。

KeywordAccountAssociation__c有多行Account__c,它們有相同的account_id,而這些account_id與自定義對象記錄Keyword__c有關。我想獲取與一個帳戶相關的所有關鍵字並更新其(多帳戶的)多選項列表。我怎樣才能做到這一點?如果您對此有疑問,請不要問。謝謝!

+0

當你說你想更新/插入DD_Segment__c的值時,你的意思是你想更新該字段中的記錄值,還是實際修改了可供選擇的選項列表選項? – JCD

+0

更新記錄 –

回答

1

的一個問題是有關學習與一般的觸發器,它可以與Salesforce Apex Developer Documents on Triggers

開始工作,但回答您的實際問題,你會基本上是需要建立一個觸發對您的自定義對象,將更新相關賬戶。它可能是這個樣子:

trigger keywordAccountUpdate on KeywordAccountAssociation__c (after insert, after update){ 
    set<id> = new set<id>(); 
    for (KeywordAccountAssociation__c a : Trigger.new) 
     accountIds.put(a.Account__c); 
    map<id,Account> accountMap = new map<id,Account>([select id, DD_Segment__c from Account where id in :accountIds]); 
    for (KeywordAccountAssociation__c kaa : Trigger.new){ 
     if (AccountMap.containskey(kaa.Account__c)){ 
      Account thisAccount = AccountMap.get(kaa.Account__c); 
      String s = thisAccount.DD_Segment__c + ';new value'; // Always add value 
      if ((thisAccount.DD_Segment__c).contains('second value') 
       s += ';second value'; 
      AccountsToUpdate.add(new Account(id=thisAccount.id, DD_Segment__c = s)); 
     } 
    } 
} 

請記住,我沒有測試這個觸發結構,我只是免費handded,所以因人而異。

+0

我從哪裏得到這個值? '新值','第二值'。我在'KeywordAccountAssociation'中存儲了'Keyword_Ids'。 –

相關問題