0

I'm at a loss. I'm updating a List via checkbox/actionsupport method and it's saving one variable but not the other. (screenshot).

Here's code:

    public class aAccount {
        public Account act {get;set;}
        public Boolean selected {get;set;}
        public Double confidencescore {get;set;}
        public aAccount(Account a) {
            act = a;
            selected = false;
            confidencescore = 0;
        }
    }
Public List<aAccount> MatchingProperties {get; set;}
Public myController() {                 // initialize
    MatchingProperties = New List<aAccount>();  }


public PageReference UpdatePropSelectedbyCheckbox(){  
    PropID=ApexPages.currentPage().getParameters().get('ID');
    for (aAccount A:MatchingProperties){

        if (A.act.Id==PropID) {       
            a.confidencescore=100;
        }            
    }    
return null;
}

VF:

<apex:pageblocktable var="properties" value="{!MatchingProperties}" id="pb">
<apex:inputCheckbox id="go" value="{!properties.selected}">
    <Apex:actionsupport action="{!UpdatePropSelectedbyCheckbox}" event="onchange" rerender="asd">
        <apex:param name="ID" value="{!properties.act.id}" assignto="{!PropID}"/>
    </Apex:actionsupport>
</apex:inputCheckbox>

If you notice the breakpoint log, there's 2 records I checked off, the most recent being item #17. The checkbox values (selected) and confidence level both show all good, but upon exit, "selected" reverts to false while keeping the newly updated confidencescore at 100. Weird huh? Any ideas on how to update the List differently? Do I need to save the selected and confidence fields into a cloned list? I dunno. I'm new to Apex so I don't know much about its memory management..

enter image description here

5
  • There's no problem with your code per se, but I suspect that you might be running in to a race condition where you're clicking too quickly, thus confusing the view state. It'd be hard to tell without additional code, though.
    – sfdcfox
    Aug 5, 2017 at 4:21
  • Okay thanks... I fixed this using a temporary variable, and then in the VF, I changed the call to the abstract... so.. public PageReference UpdatePropSelected(){ // for manual property selection PropID=ApexPages.currentPage().getParameters().get('ID'); for (aAccount A:MatchingProperties){ if (A.act.Id==PropID) { a.trick=!a.trick; if (!a.trick) a.confidencescore-=100; else a.confidencescore+=100; } } return null; }
    – J.W.
    Aug 5, 2017 at 17:16
  • Okay thanks... I fixed this adding another boolean in my wrapper, and then in the VF, I changed the call to an abstraction... so.. checkbox value={!Eitherbooleanselected} AND BAMM! I dunno why it bugged but I know I worked around it and my client will be happy now :)
    – J.W.
    Aug 5, 2017 at 17:25
  • I personally would have just put the method in the wrapper itself, which would have made it easier to do instead of looping through the entire list.
    – sfdcfox
    Aug 5, 2017 at 19:49
  • well, it seems my visualforce page was the culprit. I had a table that was throwing things off (red apex tags)... so I removed my table and bamn! wow what a great learning experience! ;-)
    – J.W.
    Aug 6, 2017 at 4:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.