public class Checkbox_Class
{
List<assetswrapper> assetsList = new List<assetswrapper>();
List<Asset> selectedAssets = new List<Asset>();
Integer x;
public List<assetswrapper> getAssets()
{
for(Asset a : [Select //Select Asset name, Serial Number, Quantity and whether it's been RMAed from Assets
SerialNumber, Name, Quantity, Returned__c, Retired__c, RMAed__c
FROM Asset
WHERE (Retired__c != true AND Returned__c != true)
limit 100] ) Limit the amount of returned Assets to 100 because of SOQL 1000 query limit.
assetsList.add(new assetswrapper(a)); //as each asset is processed, we create a new assetswrapper object and add it to the assetslist
return assetsList; // return the assetsList list when called.
}
public PageReference getSelected()
{//We create a new list of Assets that we populate only with Assets if they get selected
selectedAssets.clear(); //
//cycle through assetswrapper accwrapper list and we will check to see if the selected property is set to true,
//if it is, we add the Asset to the selectedAssets list.
for(assetswrapper accwrapper : assetsList)
if(accwrapper.selected == true)
selectedAssets.add(accwrapper.acc);
return null;
}
public void getSelected2()
{//same as the above method. Except we just want to return an integer value here to see how many assets were selected.
//selectedAssets.clear(); //
for(assetswrapper accwrapper : assetsList)
if(accwrapper.selected == true)
selectedAssets.add(accwrapper.acc);
x = selectedAssets.size();
}
public Integer GetSelectedAssets()
{
if(selectedAssets.size()>0){
x = selectedAssets.size();
return x;
}
//return selectedAssets;
else
return null;
}
//The wrapper/container class. Wrapper contains both the Asset object and a boolean value.
public class assetswrapper
{
public Asset acc{get; set;}
public Boolean selected {get; set;}
//When we create a new assetswrapper object here, we pass an asset. Selected value is also set to False.
public assetswrapper(Asset a)
{
acc = a;
selected = false;
}
}
}
The above is the code which is almost exactly similar to the create a checkbox datatable wiki on developer force: http://wiki.developerforce.com/page/Checkbox_in_DataTable
I am not trying to show 1000 items on a list. In fact, I've limited the list to only show 100 items max. However, I still get that collection size error every time I select 20+ items on that checkbox datatable. Any clues as to where I'm going wrong in the code? I see that this is a duplicate question but the other similar questions did not have the solution that I was looking for:
VISUALFORCE CODE:
<apex:page controller="Checkbox_Class" Tabstyle="Asset">
<apex:form >
<apex:pageBlock Title="Assets with CheckBoxes">
<div style="overflow:auto; width:500px; height:500px">
<apex:pageBlockSection Title="List of Available Assets">
<apex:dataTable value="{!assets}" var="a" columnswidth="50px,50px" cellpadding="4" border="1">
<!--makes a call to the getAssets() method in the Checkbox_Class Controller-->
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox>
<apex:actionSupport event="onclick" onsubmit="checkAll(this,'checkedone')"/>
</apex:inputCheckbox>
</apex:facet>
<apex:inputCheckbox value="{!a.selected}" id="checkedone"></apex:inputCheckbox>
</apex:column>
<apex:column headervalue="Asset Name" value="{!a.acc.Name}" />
<apex:column headervalue="Serial Number" value="{!a.acc.SerialNumber}" />
<apex:column headervalue="Quantity" value="{!a.acc.Quantity}" />
<apex:column headervalue="RMAed" value="{!a.acc.RMAed__c}" />
</apex:dataTable>
</apex:pageBlockSection>
</div>
<apex:pageBlockSection Title="Selected Assets" >
<apex:commandButton action="{!getSelected}" value="Create Quote"/>
<apex:outputText value="{!SelectedAssets}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script>
function checkAll(cb)
{
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf("checkedone")!=-1)
inputElem[i].checked = cb.checked;
}
}
</script>
</apex:page>