+ Start a Discussion
Salluri LeelavathiSalluri Leelavathi 

How to write a trigger on Account , when an account insert , automatically account billing address should populate into the account shipping address.

Hi, can any one help me with trigger on Account , when an account insert , automatically account billing address should populate into the account shipping address.

I wrote this but not working
trigger AddressUpdate on Account (before insert) 
{
  for(Account Acc:trigger.new)
  {
      Acc.BillingStreet=Acc.ShippingStreet;
      Acc.BillingCity=Acc.ShippingCity;
      Acc.BillingCountry=Acc.ShippingCountry;
      Acc.BillingState=Acc.ShippingState;
      Acc.BillingPostalCode=Acc.ShippingPostalCode;
  }
}
Best Answer chosen by Salluri Leelavathi
mukesh guptamukesh gupta
Hi Salluri,

Please use below code:-
 
trigger AddressUpdate on Account (before insert) 
{
  for(Account Acc:trigger.new)
  {
      Acc.ShippingStreet = Acc.BillingStreet;
      Acc.ShippingCity=    Acc.BillingCity;
      Acc.ShippingCountry= Acc.BillingCountry;
      Acc.ShippingState=   Acc.BillingState;
      Acc.ShippingPostalCode=Acc.BillingPostalCode;
  }
}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

All Answers

mukesh guptamukesh gupta
Hi Salluri,

Please use below code:-
 
trigger AddressUpdate on Account (before insert) 
{
  for(Account Acc:trigger.new)
  {
      Acc.ShippingStreet = Acc.BillingStreet;
      Acc.ShippingCity=    Acc.BillingCity;
      Acc.ShippingCountry= Acc.BillingCountry;
      Acc.ShippingState=   Acc.BillingState;
      Acc.ShippingPostalCode=Acc.BillingPostalCode;
  }
}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
This was selected as the best answer
Suraj Tripathi 47Suraj Tripathi 47
Hi Salluri Leelavathi,

Try this code:

 Trigger:
trigger AddressUpdate on Account (before insert) 
{AccountUpdate.updateAccount(trigger.new);
}

Apex:
public class AccountUpdate {
    public static void updateAccount(list<Account> acList){
        try{
            for(Account acObj:acList){
                if(acObj.BillingStreet!=null){
                    acObj.ShippingStreet = acObj.BillingStreet;
                } 
                if(acObj.BillingCity!=null){
                    acObj.ShippingCity=    acObj.BillingCity;
                }
                if(acObj.BillingCountry!=null){
                    acObj.ShippingCountry= acObj.BillingCountry;
                }
                if(acObj.BillingState!=null){
                    acObj.ShippingState=   acObj.BillingState;
                }
                if(acObj.BillingPostalCode!=null){
                    acObj.ShippingPostalCode=acObj.BillingPostalCode;
                }
            }
        }catch(Exception e){
            system.debug('Error'+e.getMessage());
        }
    }
}
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too

Thanks and Regards,
Suraj Tripathi
​​​​​​​