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
Jesper KristensenJesper Kristensen 

Visualforce action sees old value when immediate=true

I have a Visualforce page with a button, which must not perform any validations (like required value missing). These validations should only be performed later, when the user clicks another button (a save button). I use immediate="true" for that.

 

<apex:page controller="TestController">
<apex:form >
    <apex:inputField value="{!a.Description}"/>
    <apex:commandButton immediate="true" action="{!go}" value="Go"/>
    {!b}
</apex:form>
</apex:page>

public with sharing class TestController {
    public Account a {get;set;}
    public String b {get;set;}
    public Testcontroller() {
        a = new Account(Description = 'x');
    }
    public PageReference go() {
        b = a.Description;
        return null;
    }
}

 

Steps: Change the input from "x" to "y", then press Go.

Expected: "y" is printed after the Go button.

Actual: "x" is printed after the Go button.

 

If I remove the immediate attribute, it works. What happens here, and how can I fix it to print "y" in this case, without having the Go button perform validations?

Vinita_SFDCVinita_SFDC

Hi,

Try writing get set as follows:

private SomeValue;
public Account getValue() {
    return SomeValue;
}

public void setValue(Account value) {
    SomeValue = value;
}

 

Though it is similar to what you did , just give it a try.

Jesper KristensenJesper Kristensen

This didn't change anything. Here is what I tried:

 

public with sharing class TestController {
    private Account aa;
    public Account getA() {
        return aa;
    }
    public void setA(Account a) {
        aa = a;
    }
    public String b {get;set;}
    public Testcontroller() {
        aa = new Account(Description = 'x');
    }
    public PageReference go() {
        b = aa.Description;
        return null;
    }
}

<apex:page controller="TestController">
<apex:form >
    <apex:inputField value="{!a.Description}"/>
    <apex:commandButton immediate="true" action="{!go}" value="Go"/>
    {!b}
</apex:form>
</apex:page>