So I have two custom objects: The Workload_Unit_Score__c object is a mapping table, with a reference field (WLU_Combination_Value__c) and a value (Score__c) for each row reference. We receive requests each day to process contractual agreements. A new record is created on the Agreement_Title__c object for each request. Each record is assigned a Workload_Unit_Score__c, based on its WLU_Combination_Value__c.
I basically want to do something similar to an excel vlookup - each time we receive a request and a new Agreement_Title__c record is created, I want a trigger to take the WLU_Combination_Value__c, retreive a Score__c from the Workload_Unit_Score__c object, and populate that value in the Workload_Unit_Score__c field. The two custom objects are not related. Below is a summary of the fields.
-Workload_Unit_Score__c object(sort out like a "definition" or "reference" table)
- Name
- MiscField1
- MiscField2
- MiscField3
- WLU_Combination_Value__c (a formula field that concatenates MiscField1 + MiscField2 + MiscField3)
- Score__c (a score designated for each unique WLU_Combination_Value__c)
-Agreement_Title__c object(contractual agreements)
- Name
- MiscField1
- MiscField2
- MiscField3
- WLU_Combination_Value__c (a formula field that concatenates MiscField1 + MiscField2 + MiscField3)
- Workload_Unit_Score__c (a score given to each unique WLU_Combination_Value__c)
I have run the code below but I get "Compile Error: expecting right curly bracket, found '' at line 22 column 0" But I think there may be other issues with the code that wont work.
Can someone assist? Is there an easier way to do this? Sorry I'm an Apex noob...
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;
}
}
}