This might have been posted several times but i'm unable to workaround this issue using apex & I also looked at all the existing questions similar to this. I have a list of Opps with checkboxes in wrapper and i'm unable to retrieve the selections in apex where it always show false. we click on search button - searchaction() after selecting the checkboxes.Any help is really appreciated. enter image description here

<apex:page controller="ForecastQuotaUpdateController" sidebar="false" docType="html-5.0">
    <apex:form >
        <apex:pagemessages />
        <apex:pageblock >
            <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search by Acc/Owner/Parent..." title="Type in an Account Name"/>
            Year : &nbsp;
            <apex:inputField value="{!history.Year__c}"/>            
            User &nbsp;
            <apex:selectList multiselect="false" size="1" value="{!selectedUser}">
                <apex:selectOptions value="{!userOptionsList}"></apex:selectOptions>
            Team &nbsp;
            <apex:inputCheckbox value="{!isTeam}"/>            
            Confidence % &nbsp;
            <apex:inputCheckbox value="{!isOppConfidence}"/>            
            Exclude S1 &nbsp;
            <apex:inputCheckbox value="{!isS1Exclude}"/>
            Exclude S2 &nbsp;
            <apex:inputCheckbox value="{!isS2Exclude}"/>            
            Exclude S3 &nbsp;
            <apex:inputCheckbox value="{!isS3Exclude}"/>
            <apex:commandButton value="Search" action="{!searchAction}" status="status" rerender="formId"/>

    <apex:form id="formId">
        <!-- List of Opps -->
        <div id="oppstblDiv">
            <table class="oppstbl" id="myTable">
                        <th colspan="1" style="width:50px;">Select</th>
                        <th colspan="1">Opp Name</th>
                        <th colspan="1">Stage</th>
                        <th colspan="1">Budget</th>
                        <th colspan="1">Owner</th>
                        <th colspan="1">End Date</th>
                    <apex:repeat value="{!forecastOppWrapList}" var="oppWrap">
                            <td><apex:inputCheckbox value="{!oppWrap.selected}"/></td>

Here's the controller

public class ForecastQuotaUpdateController {

    public String selectedUser { get; set; }
    public Boolean isTeam { get; set; }
    public Boolean isOppConfidence { get; set; }
    public Boolean isS1Exclude { get; set; }
    public Boolean isS2Exclude { get; set; }
    public Boolean isS3Exclude { get; set; }    
    public ForecastQuotaUpdateController(){
        isTeam = false;
        isOppConfidence = false;
        isS1Exclude = false;
        isS2Exclude = false;
        isS3Exclude = false;
        selectedUser = '';
        userOptionsList = new List<SelectOption>();
        userOptionsList.add(new SelectOption('', '--None--'));
        history = new Quota_History__c();
        yearCurrent = String.valueOf(System.Today().year());
        searchUtility('', yearCurrent,'', false, false, false, false, false, new List<ForecastOpportunityListWrapper>());

    //Search Button
    public void searchAction(){
        List<SelectOption>  userOptionsListTemp = new List<SelectOption>();
        if(history.year__c != null){        
            yearCurrent = history.year__c;
        if(String.isBlank(selectedUser) && isTeam){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, 'Select a User'));        
            //Here i'm expecting "forecastOppWrapList" to have "selected" = true after selection on VFP (which isNOT working)
            searchUtility('', yearCurrent, selectedUser, isTeam, isOppConfidence, isS1Exclude, isS2Exclude, isS3Exclude, forecastOppWrapList); 

    public void searchUtility(String AccountId, String yearStr, String sltUser, Boolean isTeamUser, Boolean isOppConfidenceSet, Boolean isS1ExcludeSet, Boolean isS2ExcludeSet, Boolean isS3ExcludeSet, List<ForecastOpportunityListWrapper> tempforecastOppWrapList){       
        for(Some accs query){
             //Opportunities List S1 S2 S3
            forecastOppWrapList = new List<ForecastOpportunityListWrapper>();
            for(Opportunity tempOpp : tempClosedWon.Values()){
                ForecastOpportunityListWrapper wrapOpp = new ForecastOpportunityListWrapper(tempOpp);

            for(ForecastOpportunityListWrapper selectedOpp : tempforecastOppWrapList){
                    ...//Capture the selected opps logic

   //Wrapper Class
    public List<ForecastOpportunityListWrapper> forecastOppWrapList { get; set; }
    public Class ForecastOpportunityListWrapper{
        public Id oppId { get; set; }
        public Opportunity opp {get; set;}
        public Boolean selected {get; set;}
        public ForecastOpportunityListWrapper(Opportunity o){
            opp = o;
            selected = false;
  • Please always put even your one-line IF actions in brackets. Some Apple code broke because someone put a second line in an IF block and didn't put in brackets. It's best practice to put if{} brackets, no matter what. And it helps readability. Commented Feb 7, 2020 at 5:16
  • @DavidSchach Hi David, i updated the above code to reflect your recommendation. Can you please help me with the issue that i'm facing here?
    – Sam
    Commented Feb 7, 2020 at 21:37

1 Answer 1


Your code is a bit hard to follow. My guess is that this line and the following code:

forecastOppWrapList = new List<ForecastOpportunityListWrapper>();

is rebuilding the list (and so throwing away the selected flags) before you access the list in the following code.


  • re-implement searchUtility would be best
  • a quick fix would be to clone forecastOppWrapList if you really need both the posted (from the client) list and a newly created list in that method
  • Thanks for the response Keith. But i'm already kind of cloning the forecastOppWrapList in this line below searchUtility('', yearCurrent, selectedUser, isTeam, isOppConfidence, isS1Exclude, isS2Exclude, isS3Exclude, forecastOppWrapList); which is nothing but the tempforecastOppWrapList which I then use to pull the selected Opps.
    – Sam
    Commented Feb 6, 2020 at 21:55
  • Yeah, not quite sure how Apex handles that; passing forecastOppWrapList.clone() would be a more clear-cut duplicate of the list.
    – Keith C
    Commented Feb 6, 2020 at 22:00
  • Just tried that, still shows false
    – Sam
    Commented Feb 6, 2020 at 22:04
  • I ended up creating a separate method and separate button for this & which is working fine!
    – Sam
    Commented Feb 13, 2020 at 21:28
  • Glad you got it sorted @Sam.
    – Keith C
    Commented Feb 13, 2020 at 21:37

You must log in to answer this question.

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