title: Update Lookup Value by Trigger
body: <p>I have a custom object(custom_object__c) which contain lookup with a user,
  and I have a lookup to the custom_object__c from Opportunity, now I need to fill the custom_object__c lookup if the user lookup field present in the custom_object__c is equal to Opportunity Owner and Opportunity Stage equals Prospecting.</p>
  
  <p>My code below:</p>
  
  <p>trigger Update_Approver_Target on Opportunity (before insert, before Update) {</p>
  
  <pre><code>Set&lt;id&gt; appIds = new Set&lt;id&gt;();
  Map&lt;id, Approver_Target__c&gt; appsMap = new Map&lt;id, Approver_Target__c&gt;([SELECT Name, User__c FROM Approver_Target__c WHERE Id IN :appIds]);
  for (Opportunity opp : Trigger.new)
      appIds.add(opp.Approver_Target__c);
  
  for (Opportunity opp : Trigger.new) {
  
      System.debug('Opportunity: '+appsMap.get(opp.Approver_Target__c).User__c);
      if(opp.OwnerId == opp.Approver_Target__r.User__c &amp;&amp; opp.StageName == 'Prospecting'){
  
          opp.Approver_Target__c = opp.Approver_Target__r.Name;
      }
      else{
  
          opp.Approver_Target__c = '';
      }
  
  }
  </code></pre>
  
  <p>}</p>