title: Trigger on Account to update Contact
body: <p>Account and Contact both have Billing_Address__c field. Contact also have checkbox called active__c. If active__c is true and Account Billing_Address__c is update, then Contact's Billing_Address__c is updated . Here is the trigger. It is working fine. But I want to know if there is any problem or how can I optimize this in the terms of memory?</p>
  
  <pre><code> public static void updateContactBillingAddress(List&lt;Account&gt; lstNew, Map&lt;Id,Account&gt; mapOld){
      Set&lt;Id&gt; accIds = new Set&lt;Id&gt;();
      for(Account acc : lstNew){
          if(acc.Billing_Address__c != mapOld.get(acc.Id).Billing_Address__c &amp;&amp; acc.Billing_Address__c !=null){
              accIds.add(acc.Id);
          }
      }
      if(!accIds.isEmpty()){
          List&lt;Contact&gt; lstContact = new List&lt;Contact&gt;([Select ID,active__c, Account.Billing_Address__c,Billing_Address__c FROM Contact where AccountID IN :accIds]);
          List&lt;Contact&gt; lstUpdateCon = new List&lt;Contact&gt;();
          for(Contact con : lstContact){
              if(con.active__c == true){
                  if(con.Billing_Address__c != con.Account.Billing_Address__c){
                      con.Billing_Address__c = con.Account.Billing_Address__c;
                      lstUpdateCon.add(con); 
                    }
               }
              else{
                  con.Billing_Address__c =null;
                  lstUpdateCon.add(con); 
              }
          }
          if(!lstUpdateCon.isEmpty()){
              update lstUpdateCon;
          }
      }
  }
  </code></pre>