0

I have a VisualForce page that should pass the selected the value to the controller to update the record. See code below.

<apex:inputField value="{!l2.Status__c}">
<apex:actionSupport event="onchange" reRender="newstatus" action="{!saveChanges}" status="myStatus">
<apex:param name="statusId" value="{!l2.id}" assignTo="{!cid}"/>
<apex:param name="status" value="{!l2.Status__c}" assignTo="{!l1}"/>
</apex:actionSupport>
</apex:inputField>

When the value in inputField for {!l2.Status__c} is updated, it should pass the new value to the controller and assign to {!l1} in the controller. However, it doesn't work. If I use something such as <apex:param name="status" value="Test" assignTo="{!l1}"/>, it does pass the "Test" value to the controller and the record is update with the the value of "Test". But I cannot seem to get the user's selected value in {!l2.Status__c} to update in the record.

1 Answer 1

1

When you pass the values like that in the param you are passing the original value as the new value has not been set yet.

You should be:

<apex:inputField value="{!l2.Status__c}">
<apex:actionSupport event="onchange" reRender="newstatus" action="{!saveChanges}" status="myStatus">
<apex:param name="statusId" value="{!l2.id}" assignTo="{!cid}"/>
</apex:actionSupport>
</apex:inputField>

Then in your controller saveChanges method

l1 = l2.Status__c;

As when this is assigned the setter for l1 has fired and has the new value from the input field

This then poses the question of the need for the param at all for cID as you can just use l2.id in the controller as well. Taking it further, why use the l1 or cid at all then when you can just use the values l2.Status__c and l2.id

3
  • 1
    Use of cid is ;String cid = ApexPages.CurrentPage().getParameters().get('statusId'); String l1 = ApexPages.CurrentPage().getParameters().get('status'); System.debug('Check if value of id and status are there' + cid + l1); State_Licensing__c lic = [select Status__c from Licensing__c where Id = :cid]; lic.Status__c = l1; System.debug('Check l1 value' + lic); update lic; Commented Dec 30, 2015 at 18:07
  • Time to rethink your code and the order of execution / events maybe.......
    – Eric
    Commented Dec 30, 2015 at 18:10
  • I might approach this with an actionRegion around the inputField and no action= action; just let SFDC transmit the current value of status__c and then rerender whatever DOM elements need to be rerendered
    – cropredy
    Commented Dec 30, 2015 at 19:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .