Write a trigger Whenever ,account is inserted and checkbok CopyBillingTo Shipping is true, then automatically copy account billing address to account shipping address.

	trigger CopyBillingToShipping on Account (before insert) {
          for (Account acc : Trigger.new) {
            if (acc.CopyBillingToShipping__c == true) {
                acc.ShippingStreet = acc.BillingStreet;
                acc.ShippingCity = acc.BillingCity;
                acc.ShippingState = acc.BillingState;
                acc.ShippingPostalCode = acc.BillingPostalCode;
                acc.ShippingCountry = acc.BillingCountry;
            }
   	}
 }

trigger and a separate class:

// Trigger code
trigger CopyBillingToShipping on Account (before insert) {
    CopyBillingToShippingTriggerHandler.copyAddress(Trigger.new);
}

// Trigger handler class
public class CopyBillingToShippingTriggerHandler {
    public static void copyAddress(List accounts) {
        for (Account acc : accounts) {
            if (acc.CopyBillingToShipping__c == true) {
                acc.ShippingStreet = acc.BillingStreet;
                acc.ShippingCity = acc.BillingCity;
                acc.ShippingState = acc.BillingState;
                acc.ShippingPostalCode = acc.BillingPostalCode;
                acc.ShippingCountry = acc.BillingCountry;
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *