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
OldDeadBugOldDeadBug 

InputFields!!!! Why aren't they being set??????

Seems like the guide is trying to be clear about this, but not for me. Most of the examples in other questions I've found about this topic are WAYYYY too long to read through, so I'll try to make mine simple:

 

Here's the first part of my controller extension:

 

 

public class Controller_OppItemEdit_OverRide
{

OpportunityLineItem OLI public Controller_OppItemEdit_OverRide (ApexPages.StandardController stdController) { this.OLI = (OpportunityLineItem)stdController.getRecord(); }

Now according to the APEX Guide:

"Note that only the fields that are referenced in the associated Visualforce markup are available for querying on this SObject. All other fields, including fields from any related objects, must be queried using a SOQL expression."

 

That would seem to mean that if I reerence a field that is on the Controller Object in the VF Page, I don't have to query for it using SOQL. But from my experence, I'm not sure I believe this. To continue:

 

 

public OpportunityLineItem getOLI()
    {
    	return OLI;
    }
    
    public void setOLI(OpportunityLineItem LI)
    {
    	this.OLI = LI;
    }

 

 

Adding these getter and setter methods or the standard Controller seems redundant to me, but someone else did this in an example and said it worked for them in their instance, so I include it here. Maybe that;s the problem, maybe not - I don't know.

 

 

public PageReference Save()
    {
system.debug('MRC is '+OLI.MRC__c+' and NRC is '+OLI.NRC__c);
    	
OLI.TotalPrice = OLI.MRC__c + OLI.NRC__c;
    	
update OLI;

return null;

}

 

 

That's it for the Controller code in its simplest form. All of the fields are referenced in the VF Page as inputFields. So, I would assume that if I change one of those inputFields, and click a button that calls an Update to the record, that the record would be updated with the new values.

This assumption is clearly wrong as the record does not get updated.

Here is the essence of the Page:

 

 

<apex:page standardController="OpportunityLineItem" extensions="Controller_OppItemEdit_OverRide" >
<apex:form >
<apex:outputPanel id="thePanel">
<apex:pageBlock id="theBlock" >
<apex:pageBlockButtons >

<apex:CommandButton action="{!save}" value="Save Changes" rerender="thePanel"/>

 </apex:pageBlockButtons>
<apex:PanelGrid columns="2"> New MRC:&nbsp; <apex:inputField value="{!OpportunityLineItem.MRC__c}"/> New NRC:&nbsp; <apex:inputField value="{!OpportunityLineItem.NRC__c}"/> </apex:PanelGrid> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page>

  So that's pretty much it. I add a value to the inputField, and click the Save button. The values in the page remain, however the debug statement indicates the values being set are still null, even though the debug log says the update went through as expected. Nows the previously saved values for the record are appearing in the page, but the new values do not appear to be getting to the database.

 

To resolve this I added a query for the Line Item record in the Constructor method:

 

 

OpportunityLineItem OLI;

public Controller_OppItemEdit_OverRide (ApexPages.StandardController stdController) 
    {
        this.OLI = (OpportunityLineItem)stdController.getRecord();
         OLI=[SELECT id, OpportunityID, MRC__c, NRC__c, ...
    		 FROM OpportunityLineItem
    		 WHERE id = :OLI.id];
    }

// And then I added individual properties for each of the fields:

    public decimal MRC {get; set;}
    public decimal NRC {get; set;}

 

 

Now, I can change the inputFields into InputText boxes in the page. And because there is now a property to receive and provide these values, I can now set the OLI record values from the properties:

 

 

public PageReference Save()
    {
        if (MRC != null)
    		OLI.MRC__c = MRC;
    	if (NRC != null)
    		OLI.NRC__c = NRC;
    update OLI;
    }

 

 

This does update the values in the record, which is great - except that I'm having to write customized logic for what should be already available by virtue of using a standard controller and inputFields. I would go ahead and use this except that one of the fields I need is a picklist, and setting up the SelectOptions for a field that is already available on the object means the list of values has to be updated whenevfer someone changes them in SFDC. I realize I could write some long getDescribe method to extrsact the current set of field values, but that seems kind of stupid in this case.

When I add the inputField for this field, all of the current options are already availavble for selection - except the selection doesn't save.

 

I can only guess at this point that I'm declaring the extension incorrectly, or overwriting something but the Dev guide is pretty clear:

 

 

public class myControllerExtension {

    private final Account acct;
    
    public myControllerExtension(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }

By the way, above this example is the following statement:

   ApexPages.StandardController sc = new ApexPages.StandardController(sObject);

The example below it doesn't use this statement. Obviously its a way to create and instantiate a new Standard Controller variable, but there is no indication as to why I would want to use this statement, or if I would need to use it, or if the example below is the equivalent of this statement when used as part of an extension.

 

So, in order to actually get the values I input into the inputFields in a page using a StandardController extension, what am I missing??

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

sdf

Best Answer chosen by Admin (Salesforce Developers) 
Ron HessRon Hess

I think your page is not binding to your class variable

 

 

<apex:inputField value="{!OpportunityLineItem.MRC__c}"/>

 

 

i think this should be 

 

 

<apex:inputField value="{!OLI.MRC__c}"/>

 

 

then you are using your variable to bind to the page, i the first case you are using the standard controller record, which is not accessed in your Save() method.

 

you could also just access the getRecord() in the save method since the page is bound to the standard controller provided object  

 

basically 

!OpportunityLineItem  <>  !OLI

 

it looks like you copy from getRecord() to your local object but never the other direction on save.

 

 

All Answers

Ron HessRon Hess

I think your page is not binding to your class variable

 

 

<apex:inputField value="{!OpportunityLineItem.MRC__c}"/>

 

 

i think this should be 

 

 

<apex:inputField value="{!OLI.MRC__c}"/>

 

 

then you are using your variable to bind to the page, i the first case you are using the standard controller record, which is not accessed in your Save() method.

 

you could also just access the getRecord() in the save method since the page is bound to the standard controller provided object  

 

basically 

!OpportunityLineItem  <>  !OLI

 

it looks like you copy from getRecord() to your local object but never the other direction on save.

 

 

This was selected as the best answer
OldDeadBugOldDeadBug

Ron

 

Thanks a lot!! I knew it was something simple I was overlooking, and these kinds of fundamental oversights are the most frustrating of all.

 

So, I'm guessing that means I don't need to query the Line Item if the getRecord() call will allow me to display and modify lineitem fields in the page.Still not sure what that means for additional processing of field data in the controller methods, but I'll deal with that when it comes up.

 

Thanks again for the quick reply in time for me to get the page set up for a demo.

 

ODB