User Story
As a user, I need the system to automatically synchronize the Other Address field of a Contact record with the Mailing Address field when the "Mailing Address Is Same As Other Address" checkbox is selected. This functionality should be applied to both new Contact records and updates to existing Contact records. By automating this process, I can save time and ensure accurate address information is consistently maintained in the system.
Code
trigger ContactTrigger on Contact (before insert, before update) {
for(Contact con : Trigger.new){
if(con.Mailing_Address_Is_Same_As_Other_Address__C==true){
con.OtherCountry=con.MailingCountry;
con.OtherCity=con.MailingCity;
con.OtherPostalCode=con.MailingPostalCode;
con.OtherState=con.MailingState;
con.OtherStreet=con.MailingStreet;
}
}
}
With Handler Class
public class ContactHandler {
public static void synchronizeOtherAddress(List<Contact> contacts) {
for (Contact con : contacts) {
if (con.Mailing_Address_Is_Same_As_Other_Address__c) {
con.OtherCountry = con.MailingCountry;
con.OtherCity = con.MailingCity;
con.OtherPostalCode = con.MailingPostalCode;
con.OtherState = con.MailingState;
con.OtherStreet = con.MailingStreet;
}
}
}
}
trigger ContactTrigger on Contact (before insert, before update) {
ContactHandler.synchronizeOtherAddress(Trigger.new);
}
Video
Video does not exists.