title: Salesforce Trigger: Update field Trigger from Custom Object
body: <p>New to apex and have a question about writing triggers.  Essentially, I'm trying to create a trigger that updates a given field when another field is updated (after a record is created/inserted into Salesforce).  </p>
  
  <p>More specifically, when a custom Account lookup field (lookup value is a custom object record) is updated, it should update another field with a different value from the custom object record.</p>
  
  <p>i.e. When I update the High School name to Elm High School, it will also update the yield associated with that high school.  </p>
  
  <p>Below is the code that I've created so far:</p>
  
  <pre><code>trigger UpdateYield on Account (before update) {
  Set&lt;String&gt; HS = new Set&lt;String&gt;();
  for (Account hsName : Trigger.new) {
      if (hsName.High_School_LU__c != null) {
          HS.add(hsName.High_School_LU__c);
  }
  
  List&lt;High_School__c&gt; y = [SELECT Name, Yield__c FROM High_School__c WHERE Name IN :HS];
  
  Map&lt;String, High_School__c&gt; yLU = new Map&lt;String, High_School__c&gt;();
  for (High_School__c h : y) {            
      yLU.put(h.Name, h);    
  }
  
  for (Account YieldU : Trigger.new) {
      if (YieldU.High_School_LU__c != null) {
          High_School__c a = yLU.get(YieldU.Name);
          if (a != null) {
              YieldU.Yield__c = a.Yield__c;
          }
      }        
  }
  }
  }
  </code></pre>
  
  <p>It saves however, it still does not work when I update the field.</p>
  
  <p>Any help would be greatly appreciated.  Thanks in advance.</p>