• Robert John Lacatan
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Im new to sales force and I really don't know if my codes are good. But if update the Billing Address it would not update the mailing address in my Contact. can somebody point out what I'm missing? thanks
--------------------------------------------------------
trigger contactFromAccount on Account (after update) {
        ManagingAccountAndContacts begintrigger = new ManagingAccountAndContacts();
        
        if(Trigger.isbefore && Trigger.isupdate){
               begintrigger.isBeforeUpdate(trigger.new);
        }
}

---------------------------------------------------
public class ManagingAccountAndContacts {
        public void isBeforeUpdate(List<Account> accList){
            updateAddressToContacts(accList);
        }
    
        public void updateAddressToContacts(List<Account> accList){
             String accName = '';
            String contactmailingStreet = '';
            String contactmailingCity = '';
            String contactmailingState = '';
            String contactmailingPostalCode = '';
            String contactmailingCountry = '';
            
            for(Account acc:accList){
            accName = acc.Name;
               contactmailingStreet = acc.BillingStreet;  
            contactmailingCity = acc.BillingCity;
            contactmailingState = acc.BillingState;
            contactmailingPostalCode = acc.BillingPostalCode;
            contactmailingCountry = acc.BillingCountry;
            }
        
            List<Contact> contactList =[select MailingStreet,MailingCity, MailingState,MailingPostalCode,MailingCountry 
                         from Contact where Account.name Like:(accName)];
       
            for(Contact con: contactList){
                con.MailingStreet = contactmailingStreet;
             con.MailingCity =  contactmailingCity;
             con.MailingState = contactmailingState;
             con.MailingPostalCode = contactmailingPostalCode;
             con.MailingCountry = contactmailingCountry;
             
               }
        }
}

 
Im new to sales force and I really don't know if my codes are good. But if update the Billing Address it would not update the mailing address in my Contact. can somebody point out what I'm missing? thanks
--------------------------------------------------------
trigger contactFromAccount on Account (after update) {
        ManagingAccountAndContacts begintrigger = new ManagingAccountAndContacts();
        
        if(Trigger.isbefore && Trigger.isupdate){
               begintrigger.isBeforeUpdate(trigger.new);
        }
}

---------------------------------------------------
public class ManagingAccountAndContacts {
        public void isBeforeUpdate(List<Account> accList){
            updateAddressToContacts(accList);
        }
    
        public void updateAddressToContacts(List<Account> accList){
             String accName = '';
            String contactmailingStreet = '';
            String contactmailingCity = '';
            String contactmailingState = '';
            String contactmailingPostalCode = '';
            String contactmailingCountry = '';
            
            for(Account acc:accList){
            accName = acc.Name;
               contactmailingStreet = acc.BillingStreet;  
            contactmailingCity = acc.BillingCity;
            contactmailingState = acc.BillingState;
            contactmailingPostalCode = acc.BillingPostalCode;
            contactmailingCountry = acc.BillingCountry;
            }
        
            List<Contact> contactList =[select MailingStreet,MailingCity, MailingState,MailingPostalCode,MailingCountry 
                         from Contact where Account.name Like:(accName)];
       
            for(Contact con: contactList){
                con.MailingStreet = contactmailingStreet;
             con.MailingCity =  contactmailingCity;
             con.MailingState = contactmailingState;
             con.MailingPostalCode = contactmailingPostalCode;
             con.MailingCountry = contactmailingCountry;
             
               }
        }
}