Update Billing Address as Shipping Address using before triggers

Trigger:

/**
* @author Manoj Dega
* @date 21 July 2018
* @description Trigger for account object
*/
trigger AccountTrigger on Account (before insert, before update) {
if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)) {
AccountHelperClass.updateShipToAsBillTo(trigger.new);
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

Helper class:

/**
* @author Manoj Dega
* @date 21 July 2018
* @description Helper class for Account Trigger
*/
public class AccountHelperClass {
/**
* @author Manoj Dega
* @date 21 July 2018
* @description This method is update the Billing address to shipping address
* @Context Mode Before Insert/Before Update
*/
public static void updateShipToAsBillTo(List<Account> accountList) {
for(Account acc: accountList) {
if(acc.Same_as_BillTo__c == true) {
acc.ShippingStreet = acc.BillingStreet;
acc.ShippingCity = acc.BillingCity;
acc.ShippingState = acc.BillingState;
acc.ShippingCountry = acc.BillingCountry;
acc.ShippingPostalCode = acc.BillingPostalCode;
acc.ShippingLatitude = acc.BillingLatitude;
acc.ShippingLongitude = acc.BillingLongitude;
}
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub