+ Start a Discussion
SoozeeSoozee 

Update Field in custom object with value of another field based on button click

Hello,

In my visualforce page, I have a 'reset to default' button.

When the user clicks on this button, I want richtextfield1__c field to be rewritten with richtextfield2__c.

 

How do I do this?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SoozeeSoozee

Figured it out:

In the Controller: 

 

public myControllerExtension(ApexPages.StandardController stdcontroller) {
        a = (Object__c)stdController.getRecord();
       
  }


 public PageReference reset() {
          doReset();    
        return Apexpages.currentPage(); //refresh current page            
    }

     
    public void doReset(){
        a.comment__c = a.comment_default__c;
    } 

 

In VF Page:

<apex:form >
    <br/><font size = "5"><strong>{!$User.FirstName} {!$User.LastName}</strong></font><br/><br/>
        <apex:pageBlock mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" title="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel" title="Cancel"/>
                <apex:commandButton action="{!reset}" value="Reset to Default Text" title="Reset to default text"/>
            </apex:pageBlockButtons>
             <apex:outputfield value="{!Comment_Default__c}" rendered="false"/>
            <apex:inputtextarea rendered="true" richtext="true"  value="{!Comment__c}"/>         
        </apex:pageBlock>
    </apex:form>

All Answers

Saravanan @CreationSaravanan @Creation

Hi,

 

whether these two fields are same object or not, and which field will display in visual force page..

SoozeeSoozee

Hi - these two fields are in the same object.

 

When the page loads, I want Letter__c.Text__c to be displayed.

If the user clicks 'Reset to Default' button, I want Letter__c.Text_Default__c to be displayed and I want the value of Letter__c.Text__c to be saved with the value of Letter__c.Text_Default__c.

 

Can I store Letter__c.Text_Default__c in a variable?

Can I create a 'temporary' field on the VF page to hold the values?

 

 

Saravanan @CreationSaravanan @Creation

hi

 

you can do based on the rendering of the field in visualforce page by using reset default value button method and through controller interchange the value of the field.

SoozeeSoozee

Figured it out:

In the Controller: 

 

public myControllerExtension(ApexPages.StandardController stdcontroller) {
        a = (Object__c)stdController.getRecord();
       
  }


 public PageReference reset() {
          doReset();    
        return Apexpages.currentPage(); //refresh current page            
    }

     
    public void doReset(){
        a.comment__c = a.comment_default__c;
    } 

 

In VF Page:

<apex:form >
    <br/><font size = "5"><strong>{!$User.FirstName} {!$User.LastName}</strong></font><br/><br/>
        <apex:pageBlock mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" title="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel" title="Cancel"/>
                <apex:commandButton action="{!reset}" value="Reset to Default Text" title="Reset to default text"/>
            </apex:pageBlockButtons>
             <apex:outputfield value="{!Comment_Default__c}" rendered="false"/>
            <apex:inputtextarea rendered="true" richtext="true"  value="{!Comment__c}"/>         
        </apex:pageBlock>
    </apex:form>

This was selected as the best answer