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(Listaccounts) { 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; } } } }