+ Start a Discussion
Elizabeth BryantElizabeth Bryant 

inputText not returning entered value

Hi everyone.

I have a Visualforce page and custom controller that will update a record. I have run into an issue when I click my commandButton. The value I enter into my inputText field is not being grabbed by the controller. 

Controller: 
//inputText values
    public String changedFName {get;set;}
    public String changedLName {get;set;}

​
public void updateFields(){
      	system.debug('>>> Input FN: ' +changedFName);
        if ((changedFName == '' || changedFName == NULL) && (changedLName == '' || changedLName == NULL)){
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You must enter data to update.'));
        } 
        else if (changedFName !='' || changedFName != NULL){
            srcResult.FirstName__c = changedFName;
            update srcResult;
        } 
        else if (changedLName !='' || changedLName != NULL){
            srcResult.LastName__c = changedLName;
            update srcResult;
        }
        
        
      /*  if (changedFName != '' || changedFName != NULL) {
            try{
                system.debug('>>> Input FN: ' + changedFName);
                
                //rec.Id = caseId;
                srcResult.FirstName__c = changedFName;
                update srcResult;
                
            } catch(exception e){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Can\'t update First Name.'));
                system.debug('>>> ' + e);
            } 
        } else if (changedLName !='' || changedLName != NULL){
            try{
                system.debug('>>> Input LN: ' + changedLName);
                srcResult.LastName__c = changedLName;
                update srcResult;
            } catch (exception e){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Can\'t update Last Name.'));
                system.debug('>>> ' + e);
            }
            
        }
        else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You must enter data to update.'));
            
        } */
        
    } 

public PageReference saveRecord(){
        system.debug('>>>Button Clicked<<<');
		
       try{
           //update srcResult;
           updateFields();
           system.debug('>>> New FN: ' + srcResult.FirstName__c);
           system.debug('>>> New LN: ' + srcResult.LastName__c);
           return null;
        }
        catch(Exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Your update did not save.'));
            system.debug(e);
        }
        return null;
    }
VF Page:


<apex:form id="theForm">
            <apex:pageBlockSection >
               
                <table class="caseDetailTbl" align="center">
                    <apex:outputPanel id="detailPanel">
                        <apex:repeat value="{!srcResult}" var="details">
                            <div align="center">
                                <tr>
                                    <th align="left">Original Information</th>
                                    <td>      </td>
                                    <td>      </td>
                                    <td>      </td>
                                    <td>      </td>
                                    <td></td>
                                    <th align="right">New Information</th>
                                </tr>
                            </div>
                            <table id="updateTbl" align="center">
                                <tr><td colspan="4" style="height:25px"/></tr>
                                <tr>
                                    <td>First Name:</td>
                                    <td><apex:outputLabel id="FirstName" value="{!details.FirstName__c}"  /></td>
                                    <td>      </td>
                                    <td>      </td>
                                    <td>      </td>
                                    <td>      </td>
                                    <td><apex:inputText id="OverRide_FirstName" styleClass="trackChanges" value="{!changedFName}"/></td>
                                </tr>
                                <tr>
                                    <td>Last Name:</td>
                                    <td><apex:outputLabel id="LastName" value="{!details.LastName__c}"  /></td>
                                    <td>      </td>
                                    <td>      </td>
                                    <td>      </td>
                                    <td>      </td>
                                    <td><apex:inputText id="OverRide_LastName" styleClass="trackChanges" value="{!changedLName}"/></td>
                                </tr>
                                
                            </table>
                        </apex:repeat>
                       
                        <tr></tr>
                            <tr>
                                <td/>
                            </tr>
                                <tr width="75%">
                                    <td/>
                                    <td style="align:right;">
                                        <apex:commandButton id="cmdSave" style="font-weight: bold;align:left;" styleClass="btn btn-primary horizontalButtons" value="Save" action="{!saveRecord}" reRender="updateTbl, err">
                                           
                                        </apex:commandButton>
                                        <apex:pageMessages id="err"/>
                                    </td>
                                </tr>
                    </apex:outputPanel>
                    
                </table>
            </apex:pageBlockSection>
        </apex:form>


These are the results that I am getting for the uncommented code in updateFields() (This is WITH data entered into the fields):
 1. Errors: You must enter data to update. Your update did not save.
2. DEBUG [33] >>> Input FN: null
3. Attempt to de-reference a null object error. 

These are the results that I am getting for the commented code in updateFields() (This is WITH data entered into the fields):
 1. Errors: Can't update First Name. Your update did not save.
2. DEBUG [48] >>> Input FN: null
3. Attempt to de-reference a null object error. 


Does anyone have any idea of why my inputText value is not being passed into the controller? 
Best Answer chosen by Elizabeth Bryant
Alain CabonAlain Cabon
Hi,

You should have a list or an array as a property ( get;set ) named srcResult or getter/setter methods getSrcResult / setSrcResult in your apex class.

Could you copy/paste this part of the code?

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_controller_getter_methods.htm

In your "repeat" loop, the values of srcResult (get { ... } or just an assignment: srcResult = ...) or the return values of getSrcResult is put into the variable "details" in your Visualforce Page.

<apex:repeat value="{!srcResult}" var="details">
   <table id="updateTbl" align="center">
      <td><apex:outputLabel id="FirstName" value="{!details.FirstName__c}"  /></td>
      <td><apex:inputText id="OverRide_FirstName"styleClass="trackChanges" value="{!changedFName}"/></td>
  </table>
</apex:repeat>

changedFName should be associated with the object instance returned by srcResult  or the getter method getSrcResult.
( {!details.changedFName} )

"I have a Visualforce page and custom controller that will update a record."

... if there is only one record, you don't need a loop (repeat) but we need to see the code for the declaration of srcResult or the getter/setter methods getSrcResult / setSrcResult because that could be a list of one item.

<apex:repeat value="{!srcResult}" var="details">
   <table id="updateTbl" align="center">
      <td><apex:outputLabel id="FirstName" value="{!srcResult.FirstName__c}"  /></td>
      <td><apex:inputText id="OverRide_FirstName"styleClass="trackChanges" value="{!changedFName}"/></td>
  </table>
</apex:repeat>

Regards
Alain

All Answers

Alain CabonAlain Cabon
Hi,

You should have a list or an array as a property ( get;set ) named srcResult or getter/setter methods getSrcResult / setSrcResult in your apex class.

Could you copy/paste this part of the code?

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_controller_getter_methods.htm

In your "repeat" loop, the values of srcResult (get { ... } or just an assignment: srcResult = ...) or the return values of getSrcResult is put into the variable "details" in your Visualforce Page.

<apex:repeat value="{!srcResult}" var="details">
   <table id="updateTbl" align="center">
      <td><apex:outputLabel id="FirstName" value="{!details.FirstName__c}"  /></td>
      <td><apex:inputText id="OverRide_FirstName"styleClass="trackChanges" value="{!changedFName}"/></td>
  </table>
</apex:repeat>

changedFName should be associated with the object instance returned by srcResult  or the getter method getSrcResult.
( {!details.changedFName} )

"I have a Visualforce page and custom controller that will update a record."

... if there is only one record, you don't need a loop (repeat) but we need to see the code for the declaration of srcResult or the getter/setter methods getSrcResult / setSrcResult because that could be a list of one item.

<apex:repeat value="{!srcResult}" var="details">
   <table id="updateTbl" align="center">
      <td><apex:outputLabel id="FirstName" value="{!srcResult.FirstName__c}"  /></td>
      <td><apex:inputText id="OverRide_FirstName"styleClass="trackChanges" value="{!changedFName}"/></td>
  </table>
</apex:repeat>

Regards
Alain
This was selected as the best answer
Lukas WrightLukas Wright
ok
Thanks for the instant reply
Elizabeth BryantElizabeth Bryant
Hi,
Here's the other part of the code requested. 
 
public static ADDP_Record__c srcResult{get;set;}

 public ADDP_Record__c grabCaseID(){
        
       srcResult = [SELECT ID, Case_Num__c,FirstName__c, LastName__c, OVERRIDE_FirstName__c 
                                          FROM ADDP_Record__c
                                          WHERE Id =:caseId]; 
        system.debug('>>>>> Cases: ' + srcResult);
        return srcResult;
    }

What you suggested worked, Alain Cabon. I also had to make my srcResult variable non-static to make it work. 
I'm unsure of why I was trying to use a repeat tag on my table. I can't remember my thinking behind that decision. I appreciate the help! I had been looking that this code for a while trying to figure out the issue. I will mark your reply as the answer. 

​-Liz