+ Start a Discussion
Vikram Singh 157Vikram Singh 157 

Hi ! Here is a trigger when a custom checkbox is checked , copy billing address to shipping address

trigger CopyBillingAddtoShpAdd on Account (before insert, before update) {
    for( Account ACC : trigger.new){
    if(Check_Billing_as_Shipping__c == True){
               ACC.BillingStreet          = ACC.ShippingStreet;    
               ACC.BillingCity            = ACC.ShippingCity;  
               ACC.BillingZip/Postal Code = ACC.ShippingZip/Postal Code;    
               ACC.BillingCountry         = ACC.ShippingCountry;    
}
}
}
Best Answer chosen by Vikram Singh 157
Varun SinghVarun Singh
Hi @vikram

Sorry i was updating shipping  from billing 
Now  i have  update  right  code for this trigger
 
trigger CopyBillingAddtoShpAdd on Account(before insert, before update){

for(Account acc : Trigger.new){
    if(acc.Check_Billing_as_Shipping__c==true){
        acc.ShippingState = acc.BillingState;
        acc.ShippingStreet = acc.BillingStreet;
        acc.ShippingCountry = acc.BillingCountry;
        acc.ShippingCity = acc.BillingCity;
        acc.Shippingcountry=acc.billingcountry;
         acc.ShippingPostalCode=acc.BillingPostalCode  ;  
     }
    }
}

Make this as  best anwer if it is working.
Thanks,
varun

All Answers

Varun SinghVarun Singh
Hi @vikram
here you are doing mistake
  ACC.BillingZip/Postal Code = ACC.ShippingZip/Postal Code;    
correct postal address filed is  ACC.BillingPostalCode = ACC.ShippingPostalCode ;

 
trigger CopyBillingAddtoShpAdd on Account (before insert, before update) {

    for(Account ACC  : Trigger.new){
        If (ACC.Check_Billing_as_Shipping__c= true) {
             ACC.BillingStreet          = ACC.ShippingStreet;    
               ACC.BillingCity            = ACC.ShippingCity;  
               ACC.BillingPostalCode = ACC.ShippingPostalCode ;    
               ACC.BillingCountry         = ACC.ShippingCountry;    
        }   
    } 

}

I Hope its helpful,Please select my anser as best answer.
Vikram Singh 157Vikram Singh 157
Thanks for your help Mr. Varun , but it did not work  billing address is not still copied to shipping address
Varun SinghVarun Singh
Hi @vikram

Sorry i was updating shipping  from billing 
Now  i have  update  right  code for this trigger
 
trigger CopyBillingAddtoShpAdd on Account(before insert, before update){

for(Account acc : Trigger.new){
    if(acc.Check_Billing_as_Shipping__c==true){
        acc.ShippingState = acc.BillingState;
        acc.ShippingStreet = acc.BillingStreet;
        acc.ShippingCountry = acc.BillingCountry;
        acc.ShippingCity = acc.BillingCity;
        acc.Shippingcountry=acc.billingcountry;
         acc.ShippingPostalCode=acc.BillingPostalCode  ;  
     }
    }
}

Make this as  best anwer if it is working.
Thanks,
varun
This was selected as the best answer
Vikram Singh 157Vikram Singh 157
Yeah Thanks .