Any workaround for the bug with StandardSetController getSelected method?

I’m using a VF page and a controller to get the selected records in a view list and display some info. However the first time always fails (Related question), is there a different way to do this or a workaround to this bug (quite possible related to the Enhanced Session ID Management for Visualforce critical update)?

I’m using almost the same code as salesforce in their doc, so here is their code:

Class:

public class selectedSizeWorkaround {

    ApexPages.StandardSetController setCon;

    public selectedSizeWorkaround(ApexPages.StandardSetController controller) {
        setCon = controller;
    }

    public integer getMySelectedSize() {
        return setCon.getSelected().size();
    }
    public integer getMyRecordsSize() {
        return setCon.getRecords().size();
    }
}

Page:

<apex:page 
    standardController="Opportunity"
    recordSetVar="opportunities"
    extensions="selectedSizeWorkaround"
    showHeader="false"
    id="muopp"
>
    <apex:form id="muform">
        <apex:pageMessage 
            summary="Selected Collection Size: {!mySelectedSize}" 
            severity="info"
            id="mupms"
        />
        <apex:pageMessage
            summary="Record Set Size: {!myRecordsSize}"
            severity="info"
            id="mupmr"
        />
        <apex:pageBlock title="Opportunity Mass-Update" mode="edit" id="mub1">
            <apex:pageMessages />
            <apex:pageBlockSection id="mus1">
                <apex:inputField value="{!opportunity.stagename}" id="stagename">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputField>
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom" id="mubut">
                <apex:commandButton value="Save" action="{!save}" id="butsav"/>
                <apex:commandButton value="Cancel" action="{!cancel}" id="butcan"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
        <apex:pageBlock title="Selected Opportunities" id="muselectedlist">
            <apex:pageBlockTable value="{!selected}" var="opp" id="mutab">
                <apex:column value="{!opp.name}" id="oppname"/>
                <apex:column value="{!opp.stagename}" id="oppstage"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Answer

Unfortunately, I don’t have an answer for you in terms of a workaround.

I did spend some time trying to figure this out because I have a package that makes use of getSelected() on a list view and is in use in lots of orgs so was/am concerned about this breaking too.

I’m now of the opinion that the problem is org specific. Here are the tests that I performed:

  1. Your code in new DE Org –> failed
  2. Your code in new DE Org against my custom Object –> failed
  3. My code (unmanaged) in new DE Org against my custom Object –> failed
  4. My code (managed) in new DE Org against my custom Object –> failed
  5. Your code in my original DE Org for my package –> passed!
  6. My code in my original DE Org for my package –> passed (obviously)

Where your code = that in the OP and my code = that in my package that is in use in lots of orgs.

The pod that worked is EU1 whereas the one that failed is EU3. Any idea what pod you are on? I would say we have between 30 and 50 customers using this package and no one has reported this issue yet (though it does redirect you to the list view so the user may just not realise and think they did something wrong).

I will be creating a case with Salesforce.

Update: problem seems to be fixed now that DE org is upgraded to Winter ’15, however it seems that the getRecords().size() is not returning the correct number, at least on EU3.

Update 2: now getSelected() doesn’t seem to be working on EU1 since Winter ’15 upgrade. Doh!

Update 3: 2 bugs created, currently scheduled for fix in Spring ’15.

Attribution
Source : Link , Question Author : Jose , Answer Author : Phil Hawthorn

Leave a Comment