function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bcgbcg 

how to copy the fields

hello,

 

Anyone pls tell me how to copy one fields value in another field in salesforce on click of button. i want after filling permant address when i click on button the same will be copied in correspondence address.

 

If anyone know pls help me ot or if having any example code pls post it.

 

Thanks In advance.

rmehrmeh

Hi,

 

Can you tell if the copying of the field is on the standard page or the custom page?

The button is a standard button/cutom button?

bcgbcg

Thanks Dear for reply.

 

Am using Visualforce page. and onclick on command i want to copy the values. 

 

 

Thanks

rmehrmeh

Can you post your code?

 

bcgbcg

chk the code. in this two pageblock section one for permanent address and another for Correspondence address. i want when i click on button permanent address is copied in correspondence address. pls help me if u knw abt this hows its possible.

<apex:page standardController="Employee__c" recordSetVar="panel" extensions="Employee" >
<script>
            function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
  
     return false;
     </script>
<style>

.cField
{
width:1100px;
height:40px;
}
.bField
{
width:35px;
}
.aField
{
width:230px;
height:35px;
}

.activeTab
{
    font-family:  "Calibri";
    font-size:    15px;
    cursor:      Default;
    display:    inline;
    margin:      1px -5px 1px 5px;
    float:      left;
    padding:    3px 6px 3px 6px;
    background:    rgb(170,142,10);
    border:      1px solid;
    border-color:  rgb(120,172,255);
    border-left:  0;
    border-bottom:  0;
    border-top:    0;
    cursor:      hand;
    cursor:      pointer;
    z-index:    1;
    position:    relative;
    top:      0;
    color: rgb(256,256,256);
    font-weight: Bold;
}
.inactiveTab
{
    background-color: rgb(224,240,245);
    color: rgb(0,0,0);


}
</style> 
<apex:form >
<apex:tabPanel switchType="client" selectedTab="tabdetails" id="Employee__c" tabClass="activeTab" inactiveTabClass="inactiveTab"> 
<apex:tab label="General" name="Employee Panel" id="tab1">
<apex:detail relatedList="false" title="true"/>
<apex:pageBlock title="Employee Panel Information" mode="edit">
<apex:pageBlockSection title="Personal Particulars" columns="2" collapsible="true">
<apex:inputField value="{!Employee__c.Select_Title__c}"/>
<apex:inputField value="{!Employee__c.Name}" />
<apex:inputField value="{!Employee__c.Father_s_Name__c}" />
<apex:inputField value="{!Employee__c.Mother_s_Name__c}" />
<apex:inputField value="{!Employee__c.Gender__c}"/>
<apex:inputField value="{!Employee__c.Date_Of_Birth__c}" />
<apex:inputField value="{!Employee__c.Marital_Status__c}"/>
<apex:inputField value="{!Employee__c.Religion__c}"/>
<apex:inputField value="{!Employee__c.Mobile__c}" />
<apex:inputField value="{!Employee__c.Phone_R__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Professional Particulars" columns="2">
<apex:inputField value="{!Employee__c.Designation__c}"/>
<apex:inputField value="{!Employee__c.Department__c}"/>
<apex:inputField value="{!Employee__c.Employee_Type__c}"/>
<apex:inputField value="{!Employee__c.Employement_Status__c}"/>
<apex:inputField value="{!Employee__c.Date_Of_Joining__c}"/>
<apex:inputField value="{!Employee__c.Date_of_Leaving__c}" />
<apex:inputField value="{!Employee__c.Bank_Name__c}" />
<apex:inputField value="{!Employee__c.Account_Number__c}" />
<apex:inputField value="{!Employee__c.PAN__c}"/>
<apex:inputField value="{!Employee__c.PF_Account_Number__c}"/>
<apex:inputField value="{!Employee__c.ESI_Account_Number__c}"/>
<apex:inputField value="{!Employee__c.Passport_Number__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Permanent Address" columns="2">
<apex:inputField value="{!Employee__c.Address__c}"/>
<apex:inputField value="{!Employee__c.City_p__c}"/>
<apex:inputField value="{!Employee__c.State_UT__c}"/>
<apex:inputField value="{!Employee__c.Country_p__c}"/>
<apex:inputField value="{!Employee__c.Pin_p__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Correspondence Address" columns="2">
<apex:inputField value="{!Employee__c.Address_C__c}"/>
<apex:inputField value="{!Employee__c.City__c}"/>
<apex:inputField value="{!Employee__c.State_UT__c}"/>
<apex:inputField value="{!Employee__c.Country__c}"/>
<apex:inputField value="{!Employee__c.Pin__c}"/>
<apex:commandButton value="If same as the permanent (Click Here)"/>
</apex:pageBlockSection>

 

rmehrmeh

Hi,

 

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;
}

 

This should work for you.

Please let me know if you have any problems.