Controller:
public class thousandLimit
{
private limitWrapper[] thousandBlocks = new limitWrapper[]{};
private final integer listLimit;
public thousandLimit()
{
listLimit = 999;
}
public limitWrapper[] getthousandBlocks()
{
thousandBlocks = new limitWrapper[]{};
integer counter = 0;
integer loopCount = 0;
contact[] tmpcon = new contact[]{};
for(contact con :[select name,id from contact]){
for(integer i=0;i<40;i++){
if(counter < listLimit){
tmpcon.add(con);
counter++;
}
else{
loopCount++;
thousandBlocks.add(new limitWrapper(tmpcon,loopCount));
tmpcon = new contact[]{};
tmpcon.add(con);
counter = 0;
}
}
}
system.debug('counter--------'+counter);
system.debug('loopCount--------'+loopCount);
if(thousandBlocks.size() == 0)
{
loopCount++;
thousandBlocks.add(new limitWrapper(tmpcon,loopCount));
}
system.debug('thousandBlocks----------'+thousandBlocks.size());
return thousandBlocks;
}
public class limitWrapper
{
public contact [] contacts {get;set;}
public integer blockNumber {get;set;}
public limitWrapper(contact[] cons, integer i)
{
contacts = cons;
blockNumber = i;
}
}
}
Visualforce Page:
<apex:page controller="thousandLimit">
<apex:pageBlock >
<apex:repeat value="{!thousandBlocks}" var="block">
<apex:pageBlockTable value="{!block.contacts}" var="c">
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.id}"/>
</apex:pageBlockTable>
</apex:repeat>
</apex:pageBlock>
</apex:page>
No comments:
Post a Comment