public static void afterUpdate(List<Account> newList, List<Account> oldList){
Set<Id> accountIds = new Set<Id>();
for ( Integer i=0;i<newList.size();i++ ){
if ( newList[i].BillingStreet != oldList[i].BillingStreet ){
accountIds.add(newList[i].Id);
}
}
List<Contact> contactsToUpdate = new List<Contact>();
for ( Contact c : [
SELECT Id, MailingStreet, Account.BillingStreet
FROM Contact
WHERE AccountId IN :accountIds
]){
if ( c.MailingStreet != c.Account.BillingStreet ){
c.MailingStreet = c.Account.BillingStreet;
contactsToUpdate.add(c);
}
}
if ( contactsToUpdate.size() > 0 ){
update contactsToUpdate;
}
}