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
Cindy NormanCindy Norman 

Total newbie question - value from inputField not reflected in my custom object

Hi-I'm sure this is a no-brainer for all of you guys but i'm having trouble with this. I'll be general because i'm not sure what part of my code is messed up.

************
I have some apex:inputFields that display data from a custom object- this works fine

                 <apex:outputLabel value="Number of Dependents on Application" styleClass="inputFieldLabelStyle"/>
                 <apex:inputfield value="{!application.numberOfDependents__c }" styleClass="inputFieldStyle"/>
              </apex:pageBlockSectionItem>
*************
AND a button that fires correctly when the user clicks it:

            <apex:commandButton value="Save and Continue" style="width:180px;" action="{!SaveApp}" immediate="true" rerender="ApplicationSubTabPanel,showmsgs"/>
**************
And the method defined in the controller:
    public PageReference SaveApp() 
    {
        try {        
                upsert(application);
        } catch(System.DMLException e) {      ....       }
        return null; //tells VF to refresh page.    
    }//end PageReference SaveApp()

**********
Pretty easy stuff. But the values never get saved in the DB. Any silliness that i have overlooked? an "onchange" or ?

Thank you!!
kaustav goswamikaustav goswami
You have specified the attribute immediate = true in the command button. This will tell the control to stop looking at the values present in the page and go to the method in the controller immediately. Please remove that and try. If you have placed the immediate = true attribute to serve some different purpose like bypassing other validations then you will have to take a different approach. Please let me know.

Thanks,
Kaustav
Varun PareekVarun Pareek
Please do not use immediate="true" in your button tag, it does not reflect changes to the Server. It is generally used to override page level validations. try this:
 <apex:commandButton value="Save and Continue" style="width:180px;" action="{!SaveApp}" immediate="false" rerender="ApplicationSubTabPanel,showmsgs"/>
Cindy NormanCindy Norman
Thanks you guys! 
I put immediate=true in there because it kept some validations from firing (upon upsert) on a related object (which seemed stupid to me but i couldn't get around that any other way.)
Hmmm...In your highly valued opinions, what would you suggest? 
Keeping validation from firing some other way OR
Convincing VF to get my values some other way?

I surely wish SF would document this super valuable info you guys are giving me!
Thank you!

 
Varun PareekVarun Pareek
I would recommend the validations to fire, a few of them may be looking at data integrity. To forcibly bypass them may defeat their purpose at the first place. Per MVC paradigm, your controller should respect the model validations/rules.
Cindy NormanCindy Norman
I totally agree that i don't want to bypass validation...Problem is this:
I have a custom object "application__c" and a related list of applicants__c linked by a master-detail relationship.

On the first tab, i have the application__c fields. In another tab, i have the input fields for the applicant.

Trouble is, the user has only input the application__c values and hasn't gotten to the tab to input the applicants yet.
But i want to save the application data before proceeding to the applicant input.
And doing a "Save"/upsert of the application object/record fails because there are no values in the applicant fields yet.
It is kicking off the validation rules for the related list: applicants__c!
Seems superbly stupid to me to require this...so i must be messing something up there.

So, by putting "immediate" in there, it didn't give me errors on the applicant input (i'm guessing you saying
it isn't checking the application input either? not good.)

I'm in a catch-22...trying to get around this firing of validation rules on my related object and also trying to
have my values saved in the database.

Seems that something is wrong...SF can't possibly be working this way on purpose....
kaustav goswamikaustav goswami
If you do need to keep the immediate attribute on your page. Thn you will have to modify the way your page talks to your controller and passes the values. I tried to quickly provide you some sample code.

You can try this out.
 
VF Page
=======
<apex:pageBlockSectionItem>
	<apex:outputLabel value="Number of Dependents on Application" styleClass="inputFieldLabelStyle"/>
	<apex:inputText id="numOfDepInput" styleClass="inputFieldStyle"/>
</apex:pageBlockSectionItem>

<apex:commandButton value="Save and Continue" style="width:180px;" onclick="callSaveAction();return false;"/>

<apex:actionFunction name="executeSave" action="{!SaveApp}" immediate="true" reRender="ApplicationSubTabPanel,showmsgs">
	<apex:param name="numDependents" value="" />
</apex:actionFunction>

<script type="text/javascript">
	function callSaveAction(){
		var numDep = document.getElementById("...the fully qualified exact dom id of the input field...will end with numOfDepInput").value;
		executeSave(numDep);
	}
</script>
 
Apex Controller
===============
public PageReference SaveApp(){
	try{
		String depNum = ApexPages.currentPage().getParameters().get('numDependents');
		if(depNum != null){
			application.numberOfDependents__c = depNum;
		}
		upsert application;
	}catch(Exception Ex){
		System.debug('#### error while executuion #### ' + Ex.getMessage());
	}
	return null;
}

What we are trying to do hre in this code is still keep the immediate attribute but pass the user entered value as a parameter to the controller.

Thanks,
Kaustav
Varun PareekVarun Pareek
Alternatively, you can remove the required attributes from he page. Of course they would be applied at the object level but at least you would not have to use immediate="true". So it would look something like:
<apex:inputfield value="{!applicant.application__c }" styleClass="inputFieldStyle" required="false"/>
Cindy NormanCindy Norman

You guys have convinced me to leave the immediate="true" in there on my "SaveApp" button
and, it seems, cleanest to use the required="false" on my applicant input on the other tab.
But i hate to do this (because it makes the UI less informative) and am surprised i have to.

It comes down to this question: ?????
When i do my upsert of my application__c object/record, **why** is it doing validation checks on my applicant__c information???
yes, they are related thru a master-detail relationship but...that can't be the reason, is it?
 
kaustav goswamikaustav goswami
Can you please check if there are any triggers that are running when you do an update or insert on the application__c (parent) object? Other than this I cannot think of anything else that would make the validation rules trigger on the child object when you create a record in the parent object.

Thanks,
Kaustav
Cindy NormanCindy Norman
When i go to the "Custom Object Definition Detail", it says "No Triggers Defined". Is there anywhere else something can be defined?