+ Start a Discussion
boihueboihue 

Question regarding apex:inputField

Hi,
I am developing a new Visualforce Page using the Extensions option on a new Apex Controller named OpportunityProductController. In this Visualforce Page, I'm using the apex:inputField for a Picklist field (Section__c). In the Save function of the OpportunityProductController Apex Controller how can I retrieve the value of this Section__c Picklist that was selected by the user? I need to save this value into another Custom object that's why I need to retrieve its value. Is there any Apex component that we can use for having a Calendar like the apex:inputField based on the Date field of Salesforce object?
 
Code:
<apex:page standardController="OpportunityLineItem" extensions="OpportunityProductController" title="Product" tabStyle="Opportunity">
  <apex:sectionHeader title="Opportunity / Product">
    <apex:form>
        ...     
        <apex:inputField id="cwSection" value="{!OpportunityLineItem.Section__c}" />
        <apex:inputField id="cwService" value="{!OpportunityLineItem.ServiceDate}" />
        ...
    </apex:form>
  </apex:sectionHeader>
</apex:page>
 
 
public class OpportunityProductController {
 
    public PageReference Save()
    {
      // Apex Codes (Retrieving of Section__c value)
    }
}


 
Thanks for the help!
Boi Hue
Sam.arjSam.arj
The controller typically writes it back to
OpportunityLineItem.Section__c



boihueboihue

Thansk Sam for your quick response!

But how can I code in my Apex Controller to retrieve the latest value of OpportunityLineItem.Section__c selected by the user?

Regards!

Ron HessRon Hess
The new values input by the user are stored into the controller record for you, use getRecord() to retrieve it, here is an example that will show the new value and save it :

Code:
public class OpportunityProductController {

public PageReference Save()
{
OpportunityLineItem oli = (OpportunityLineItem)controller.getRecord();
 System.debug( 'new value entered is ' + oli.Section__c );
// save the changes
return controller.save();
 } }


this assumes a variable in your extension called controller, initialize this from your constructor.
 
Ron HessRon Hess
here is a more complete example, i used standard fields to make it simpler for me.

Code:
<apex:page standardController="OpportunityLineItem" extensions="myControllerExtension" title="Product" tabStyle="Opportunity">
  <apex:sectionHeader title="Opportunity / Product">
    <apex:form >
        <apex:commandButton action="{!save}" value="save "></apex:commandButton>    
        <apex:inputField id="cwSection" value="{!OpportunityLineItem.TotalPrice}" />
        <apex:inputField id="cwService" value="{!OpportunityLineItem.ServiceDate}" />
        ...
    </apex:form>
  </apex:sectionHeader>
</apex:page>

 

and controller:

Code:
public class myControllerExtension {

    private final ApexPages.StandardController controller;
    
    // The extension constructor initializes the private member
    // variable acct by using the getRecord method from the standard
    // controller.
    public myControllerExtension(ApexPages.StandardController stdController) {
        this.controller = stdController;
    }

 
    public PageReference Save()
    {
      OpportunityLineItem  oli = (OpportunityLineItem)controller.getRecord();
      System.debug( 'new value entered is ' + oli.totalprice );
      // save the changes
      return controller.save();
    }
 
}

 

boihueboihue

It's working perfectly. Thanks for your help.

Best regards!