+ Start a Discussion
CloudyJoshCloudyJosh 

Copy billing address to shipping address in account page

So lets say I have a billing name / shipping name on the account page, and I want to be able to copy the info from the billing name field to the shipping name field, and vie versa with a click of a button, so the user doesn't have to reenter everything, how can this be done?

Cliff:
Two forms on the account page, billing and shipping name
I need to copy billing name to shipping name, and vice versa
I need this done with a click of a button (there will be 2 buttons)

Any help is appreciated!

The below code is what one of the users gave me, but I don't know how to implement this.
Behavior: Execute JavaScript
    {!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")} 

    var c = new sforce.SObject("Account"); 
    c.id = "{!Account.Id}";
    result = sforce.connection.update([c]); 

    window.location.reload();

 
Best Answer chosen by CloudyJosh
JyothsnaJyothsna (Salesforce Developers) 
Hi Josh,

Please try the below sample code.Change the object name in the below code.
Step 1: First create a visualforce page 
 
<apex:page controller="Custombutton" action="{!save1}" showHeader="false">
 
</apex:page>

Controller
 
public with sharing class Custombutton {
public customer__c ct=new  customer__c();
 public Custombutton (){
  string c=apexpages.currentpage().getparameters().get('id');
  ct=[select name,id,Billing_City__c,Billing_Postal_Code__c,Billing_State1__c,Billing_Street__c,Shipping_City__c,Shipping_Postal_Code__c,Shipping_State__c,Shipping_Street__c from customer__c where id=:c];
  
 }

    public PageReference save1() {
    ct.Shipping_City__c=ct.Billing_City__c;
    update ct;
    pagereference pr=new pagereference('/'+ct.id);
        return pr;
    }


}

Step2: Create a custom button 

User-added image



Step3: Add Detailpage button to page Layout

User-added image




Hope this helps you!
Best Regards,
Jyothsna

All Answers

JyothsnaJyothsna (Salesforce Developers) 
Hi Josh,

Please try the below sample code.Change the object name in the below code.
Step 1: First create a visualforce page 
 
<apex:page controller="Custombutton" action="{!save1}" showHeader="false">
 
</apex:page>

Controller
 
public with sharing class Custombutton {
public customer__c ct=new  customer__c();
 public Custombutton (){
  string c=apexpages.currentpage().getparameters().get('id');
  ct=[select name,id,Billing_City__c,Billing_Postal_Code__c,Billing_State1__c,Billing_Street__c,Shipping_City__c,Shipping_Postal_Code__c,Shipping_State__c,Shipping_Street__c from customer__c where id=:c];
  
 }

    public PageReference save1() {
    ct.Shipping_City__c=ct.Billing_City__c;
    update ct;
    pagereference pr=new pagereference('/'+ct.id);
        return pr;
    }


}

Step2: Create a custom button 

User-added image



Step3: Add Detailpage button to page Layout

User-added image




Hope this helps you!
Best Regards,
Jyothsna
This was selected as the best answer
Ravi Dutt SharmaRavi Dutt Sharma
Hi,

Do you have the buttons on account standard detail page or have you created a visualforce page for this?
CloudyJoshCloudyJosh
Thanks! I'll try that as soon as I can fix the visualforce developer console, it's not letting me create new apex classes...