2016-05-05 5 views
0

私は2つのカスタムオブジェクトを持っています:Workload_Unit_Score__cオブジェクトは、参照フィールド(WLU_Combination_Value__c)と各行参照の値(Score__c)を持つマッピングテーブルです。当社は契約上の契約を処理するために毎日要求を受けます。新しいレコードは、各要求ごとにAgreement_Title__cオブジェクトに作成されます。各レコードには、そのWLU_Combination_Value__cに基づいてWorkload_Unit_Score__cが割り当てられます。vlookupのような値をSalesforceで取得するApexコードですか?

私は基本的にExcelのような何かをしたいと思っています - 要求を受け取り、新しいAgreement_Title__cレコードが作成されるたびに、WLU_Combination_Value__cを取得し、Workload_Unit_Score__cオブジェクトからScore__cを取得し、 Workload_Unit_Score__cフィールドに値を入力します。 2つのカスタムオブジェクトは関連していません。以下は、フィールドの概要です。

-Workload_Unit_Score__cオブジェクト( "定義" または "参照" テーブルのように整理)

  • MiscField1
  • MiscField2
  • MiscField3
  • WLU_Combination_Value__c(式フィールドそのMiscField1 + MiscField2 + MiscField3)を連結します。
  • Score__c
  • MiscField1にそれぞれユニークWLU_Combination_Value__c)

-Agreement_Title__cオブジェクト(契約上の合意)

  • Nameにignated
  • MiscField2
  • MiscField3
  • WLU_Combination_Value__c(MiscField1を連結式フィールド+ MiscField2 + MiscField3)
  • Workload_Unit_Score__c(それぞれユニークWLU_Combination_Value__cに与えられたスコア)

は、私は以下のコードを実行しているが、私は「コンパイルエラー:行22列0で 『』見つかった右中括弧を、期待」を取得しかし、私はそこかもしれないと思います動作しないコードに関するその他の問題。

誰かが助けることができますか?これを行う簡単な方法はありますか?

trigger updateWLUvalue on Agreement_Title__c (before insert) { 

    Map<String,Agreement_Title__c[]> relatedScores = new Map<String, Agreement_Title__c[]>(); 

    for (Agreement_Title__c agmtt : trigger.new) { 
     if(!relatedScores.containsKey(agmtt.WLU_Combination_Value__c)){ 

      relatedScores.put(agmtt.WLU_Combination_Value__c, new Agreement_Title__c[]{}); 
    } 

    relatedScores.get(agmtt.WLU_Combination_Value__C).add(agmtt); 

    for(Workload_Unit_Score__c wus : [Select Id, Score__c, WLU_Combination_Value__c 
              FROM Workload_Unit_Score__c 
              WHERE WLU_Combination_Value__c 
              IN : relatedScores.keySet()]){ 
     for(Agreement_Title__c agmtt2 : relatedScores.get(wus.WLU_Combination_Value__c)){ 
      agmtt.Workload_Unit_Score__c = wus.Score__c; 
      } 
     } 
} 

答えて

0

最初のものは最後に欠けているclose-curlybracketです。最初のIFステートメントが終了しませんでした。 パッチコード:

trigger updateWLUvalue on Agreement_Title__c (before insert) { 

    Map<String,Agreement_Title__c[]> relatedScores = new Map<String, Agreement_Title__c[]>(); 

    for (Agreement_Title__c agmtt : trigger.new) { 
     if(!relatedScores.containsKey(agmtt.WLU_Combination_Value__c)) { 

      relatedScores.put(agmtt.WLU_Combination_Value__c, new Agreement_Title__c[]{}); 
     } 
    } 

    relatedScores.get(agmtt.WLU_Combination_Value__C).add(agmtt); 

    for(Workload_Unit_Score__c wus : [Select Id, Score__c, WLU_Combination_Value__c 
              FROM Workload_Unit_Score__c 
              WHERE WLU_Combination_Value__c 
              IN : relatedScores.keySet()]) 
    { 
     for(Agreement_Title__c agmtt2 : relatedScores.get(wus.WLU_Combination_Value__c)) { 
      agmtt.Workload_Unit_Score__c = wus.Score__c; 
     } 
    } 
} 
関連する問題