0

I have an object VF_Page_Update__c which has a picklist field called VF_Page_Picklist__c and a textArea(255) field Update__c. I am dynamically showing the picklist values in the Visualforce page I created called 'UpdatePageVF'. Now what I want is when I change the picklist value in VF_Page_Picklist__c and change the text in Update__c from the VF page and click on Save button, then that value will be updated in database. Currently, the VF_Page_Picklist__c value gets changed, but the value in Update__c remains the same old value even after clicking on Save. What am I doing wrong?

Apex class 'UpdateController'

public with sharing class Update_Controller {
public VF_Page_Update__c mcc {get; private set;}
private final VF_Page_Update__c speaker;

private ApexPages.StandardController stdController;
public Update_Controller(ApexPages.StandardController stdcontroller) {
 mcc= [select Id,name,VF_Page_Picklist__c, Update__c from VF_Page_Update__c WHERE id = :ApexPages.currentPage().getParameters().get('id')];
  this.speaker = (VF_Page_Update__c)stdController.getRecord();
        this.stdController = stdController;
  }
  public List<SelectOption> getVFPageList()
{
  List<SelectOption> options = new List<SelectOption>();

   Schema.DescribeFieldResult fieldResult =
 VF_Page_Update__c.VF_Page_Picklist__c.getDescribe();
   List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

   for( Schema.PicklistEntry f : ple)
   {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
   }       
   return options;
}
 public PageReference saveClose() {


     update speaker;

      return null;


    }

}

Visualforce page 'UpdatePageVF'

<apex:page standardController="VF_Page_Update__c" extensions="Update_Controller" >
   <apex:form >
   <apex:pageBlock mode="edit">

            <apex:pageMessages />

            <apex:pageBlockSection columns="1" >
<apex:inputField value="{!mcc.Update__c}"/> <p/>
<apex:selectList id="countries" value="{!VF_Page_Update__c.VF_Page_Picklist__c}"
         size="1" required="true">
  <apex:selectOptions value="{!VFPageList}"/>

</apex:selectList>


       <apex:commandButton value="Save" action="{!saveClose}"/>

</apex:pageBlockSection>
</apex:pageBlock>
    </apex:form>

</apex:page>

This code only updates the VF_Page_Picklist__c but not the Update__c.Please help and provide me the corrected code if possible.

0

Try the below code

You don't actually need two objects of VF_Page_Update__c in the Controller.

Controller

public with sharing class Update_Controller {
    //public VF_Page_Update__c mcc {get; private set;}
    public VF_Page_Update__c speaker;

    //private ApexPages.StandardController stdController;
    public Update_Controller(ApexPages.StandardController stdcontroller) {
      this.speaker = (VF_Page_Update__c)stdController.getRecord();
      //this.stdController = stdController;
    }
    public List<SelectOption> getVFPageList()
    {
      List<SelectOption> options = new List<SelectOption>();

       Schema.DescribeFieldResult fieldResult =
       VF_Page_Update__c.VF_Page_Picklist__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

       for( Schema.PicklistEntry f : ple)
       {
          options.add(new SelectOption(f.getLabel(), f.getValue()));
       }       
       return options;
    }
    public PageReference saveClose() {
         update speaker;
          return null;
    }

}

VF PAGE

<apex:page standardController="VF_Page_Update__c" extensions="Update_Controller" >
   <apex:form >
   <apex:pageBlock mode="edit">

            <apex:pageMessages />

            <apex:pageBlockSection columns="1" >
<apex:inputField value="{!VF_Page_Update__c.Update__c}"/> <p/>
<apex:selectList id="countries" value="{!VF_Page_Update__c.VF_Page_Picklist__c}"
         size="1" required="true">
  <apex:selectOptions value="{!VFPageList}"/>

</apex:selectList>


       <apex:commandButton value="Save" action="{!saveClose}"/>

</apex:pageBlockSection>
</apex:pageBlock>
    </apex:form>

</apex:page>
2
  • Thank you. This works!! Can you tell me where I was going wrong? – SFDC_CRM Jan 19 '17 at 12:25
  • You were updating an Object that was not referring to the Text area in VF it was a different object. So you just need 1 object – RCS Jan 19 '17 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.