Print this page

How to copy one set of field values to another set of fields in a custom Visual force page.

Knowledge Article Number 000175607
Description

Customer would like to know how he can copy one set of field values to another set of fields in a custom Visual force page?

Resolution

Follow the steps given below:

 

  • In your controller method first declare a variable as:   public Employee__c objEmp{get;set;}
  • Then in your constructor: objEmp= (Employee__c)write the name you have passed in controller.getRecord();
  • Add an action to your commandButton: <apex:commandButton value="If same as the permanent (Click Here)" action="{!copySameAddress}" rerender="assign ids to pageBlockSection which you wish to copy and then mention that id here"/>
  • Then in your Apex controller do the following:
public PageReference copySameAddress()
{
   if(objEmp!= null)
   {
     if(objEmp.Address__c != null && objEmp.Address__c != '')// i am assuming that this is text field
     {
          objEmp.Address_C__c = objEmp.Address__c;
        }
        // put remaining fields the same way as put above.
        // last if you want to update the same thing in the database at the click of the button just add this statement commented below
       // update objEmp;
    }
    return null;
}
 




promote demote