function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vamsivangavamsivanga 

Collection size 9999 exceeds maximum size 1000

Not sure how to overcome this.. Works pretty good in sandbox but when deployed , few users get this message while others are doing pretty well..

All I'm trying to do is, I created a visual force page for an object CLAIM and had a button to it called "Get More Claims" when ever the user clicks it, they get 10 extra claims in the order of oldest first... Please guide me here

This is my controller..


public class DemoClaimManagerController {

    public DemoClaimManagerController() {
      displayerrormessage=NoOpenClaimsNotification= false; 
    }

    private string returnurlstr;
    public boolean NoOpenClaimsNotification {get;set;}
    public boolean displayerrormessage{get;set;}
    public List<claim__c> selectedClaims{get;set;}
    public List<claim__c> myclaims{get{
        return [select Id,OwnerId,Name,Account__c,Type__c,Sub_Type__c,Status__c,Owner.alias
                            from Claim__c
                            where OwnerId = :UserInfo.getUserId()
                            and status__c != 'Processed'];//Change made from received to Processed
    }}
    public DemoClaimManagerController(ApexPages.StandardController controller){
        /*if(ApexPages.currentpage().getparameters().containskey('retURL'))
            this.returnurlstr = ApexPages.currentpage().getparameters().get('retURL');
        else
             this.returnurlstr = '/apex/DemoClaimManager';*/
        displayerrormessage = false;
        NoOpenClaimsNotification= false;
    }

    /*public List<ClaimData> getChartData() {
        List<ClaimData> data = new List<ClaimData>();
        Map<String,Integer> DatevsRecCount = new Map<String,Integer>();
        for(Claim__c singleclaim : [Select Id, CreatedDate
                                   from Claim__c
                                   where CreatedDate = LAST_N_DAYS: 7])
        {
            //DatevsRecCount.put(String.valueof(agr.get('CreatedDate')), Integer.valueof(agr.get('reccount')));
            if(DatevsRecCount.containsKey(String.valueof(singleclaim.CreatedDate.date())))
                DatevsRecCount.put(String.valueof(singleclaim.createdDate.date()),DatevsRecCount.get(String.valueof(singleclaim.createdDate.date()))+1);
            else
                DatevsRecCount.put(String.valueof(singleclaim.CreatedDate.date()),1); 
        }
        for(String Day: DatevsRecCount.keyset())
            data.add(new claimData(String.valueof(Day),DatevsRecCount.get(Day)));   
        return data;
    }*/

   /*public class ChartData {
      public String name {get; set;}
      public Integer data {get; set;}
    
     
      public ChartData (String name, Integer data) {
         this.name = name;
         this.data = data;
      }

   }*/

   public List<ClaimData> getClaimDataPersonalqueue() {
      List<ClaimData> data = new List<ClaimData>();
      Map<String,Integer> OwnervsRecCount = new Map<String,Integer>();
      for(claim__c singleclaim : [Select Id, Owner.name
                                    from Claim__c
                                    where (Status__c !='Processed' AND CreatedDate = LAST_N_DAYS: 7)])// Change made from received to Processed
           {
               //ownervsRecCount.put(String.valueof(agr.get('Owner.name')), Integer.valueof(agr.get('reccount')));
               if(OwnervsRecCount.containsKey(singleclaim.owner.Name))
                  OwnervsRecCount.put(singleclaim.Owner.name,OwnervsRecCount.get(singleclaim.Owner.Name)+1);
               else
                  OwnervsRecCount.put(singleclaim.Owner.name,1);
           }
       for(String Owner: OwnervsRecCount.keyset())
           data.add(new claimData(Owner,OwnervsRecCount.get(Owner)));   
    
      return data;
   }

   // wrapper class to hold data
   public class ClaimData {
      public String name {get; set;}
      public Integer data {get; set;}
      public ClaimData (String name, Integer data) {
         this.name = name;
         this.data = data;
      }
   }
  
   /*public Integer GetNextClaims() {
     return 0;
   }*/
   Private boolean ValidateUser(){
       List<claim__c> OwnedClaims = [select Id,OwnerId
                                        from Claim__c
                                        where OwnerId = :UserInfo.getUserId()
                                            AND Status__c != 'Processed'];
       if(!OwnedClaims.isEmpty())
       {
           return false;
       }
       return true;
   } 
   
   
    public PageReference GetMoreClaims(){  
        //PageReference retunurl= new Pagereference(returnurlstr);
        if(!validateUser())
        {
            displayerrormessage = true; 
            return null;
        }
        selectedClaims= new List<claim__c>();
        QueueSobject claimprocessor = [select queueid
                                                        from QueueSobject
                                                        where SobjectType = 'Claim__c'
                                                            AND Queue.DeveloperName = 'ClaimProcessors' limit 1];
        Id claimprocessorId = claimprocessor.queueid;
        for(claim__c claim: [Select Id,OwnerId,Name,Account__c,Type__c,Sub_Type__c,Status__c,Owner.alias
                                                        from Claim__c
                                                            where ownerId = :claimprocessorId
                                                            ORDER BY CreatedDate ASC LIMIT 20])
        {
            claim.ownerId = UserInfo.getUserId();
            selectedClaims.add(claim);
        }
        try{
            if(!selectedClaims.isEmpty())
            {
                update selectedClaims;
            }
            else
            {
                NoOpenClaimsNotification = TRUE; return null;
            }
        }
        catch(Exception e){
            System.debug('Error Updating Records'+e.getMessage());
        }
        return null;
    }
   
    public PageReference GoTOPreviousScreen(){
       displayerrormessage = false;
       NoOpenClaimsNotification  = false;  
       selectedclaims = null;
       return null;  
   }

}
logontokartiklogontokartik
can you please post the Visualforce page?
vamsivangavamsivanga
Here is my VF


<apex:page controller="DemoClaimManagerController" tabStyle="Claim__c">
    <apex:form >
    <apex:pageBlock id="MainPageBlock" >
    <apex:outputPanel rendered="{!OR(displayerrormessage,NoOpenClaimsNotification )}">
    <apex:pagemessage summary="Sorry further claims won't be released until you work on the ones you already own" severity="warning" strength="3" rendered="{!displayerrormessage}" />
    <apex:pagemessage summary="No more Open Claims are present in the claim queue processor to be transferred. " severity="Info" strength="3" rendered="{!NoOpenClaimsNotification }" />
     <apex:commandLink value="Go To Previous Screen" action="{!GoTOPreviousScreen}" rerender="MainPageBlock" />
    </apex:outputPanel>
    <!--from here-->
     <apex:pageBlockSection columns="1" Title="Claim Processing Options" rendered="{!AND(NOT(displayerrormessage),NOT(NoOpenClaimsNotification))}">
     <apex:commandButton action="{!GetMoreClaims}" value="Get More Claims" id="btnGetMoreClaims" reRender="MainPageBlock"/>
     <apex:pagemessage summary="The following Claims are Transfered To You" rendered="{!NOT(ISNULL(selectedclaims))}" severity="info" strength="1"/>
     <apex:outputPanel rendered="{!NOT(ISNULL(selectedclaims))}">
      <apex:pageblockTable value="{!selectedclaims}" var="claim">
          <apex:column headerValue="Tracking Number">
          <apex:outputLink value="/{!Claim.id}" >{!Claim.Name}</apex:outputlink>
          </apex:column>
          <apex:column value="{!claim.Account__c}" />
          <apex:column value="{!claim.Type__c}" />
          <apex:column value="{!claim.Sub_Type__c}" />
           <apex:column value="{!claim.Status__c}" />
          <apex:column value="{!claim.Owner.alias}" />
      </apex:pageblockTable>
      </apex:outputPanel>
      <apex:outputPanel rendered="{!AND(NOT(ISNULL(Myclaims)),ISNULL(selectedclaims))}" >
      <apex:pageblockTable value="{!Myclaims}" var="claim">
          <apex:column headerValue="Tracking Number">
          <apex:outputLink value="/{!Claim.id}" >{!Claim.Name}</apex:outputlink>
          </apex:column>
          <apex:column value="{!claim.Account__c}" />
          <apex:column value="{!claim.Type__c}" />
          <apex:column value="{!claim.Sub_Type__c}" />
           <apex:column value="{!claim.Status__c}" />
          <apex:column value="{!claim.Owner.alias}" />
      </apex:pageblockTable>
        </apex:outputPanel>
    </apex:pageBlockSection><!--up to here-->
   
    <apex:pageBlockSection columns="2" Title="Claim Processing Performance">
 
    <apex:pageBlockSectionItem >
       <apex:chart height="300" width="400" data="{!ClaimDataPersonalQueue}">
           <apex:axis type="Category" position="left" fields="name" title="User"/>
           <apex:axis type="Numeric" position="bottom" fields="data" title="Claims"/>
           <apex:barSeries orientation="horizontal" axis="bottom" xField="data" yField="name"/>
       </apex:chart>
    </apex:pageBlockSectionItem>
    <!--<apex:pageBlockSectionItem >
         <apex:chart height="300" width="400" data="{!ChartData}">
             <apex:axis type="Category" position="left" fields="name" title="Data"/>
             <apex:axis type="Numeric" position="bottom" fields="data" title="Claims Queued"/>
             <apex:barSeries orientation="horizontal" axis="bottom" xField="data" yField="name"/>
             <apex:lineSeries axis="left" fill="true" xField="name" yField="data" markerType="cross" markerSize="4" markerFill="#FF0000" />
        </apex:chart>
    </apex:pageBlockSectionItem>-->
    </apex:pageBlockSection>
   
    <!--put it here-->

    </apex:pageBlock>
           </apex:form>
</apex:page>
James LoghryJames Loghry
The limit is likely coming from your iterator in Visualforce, or in otherwords this line: 
<apex:pageblockTable value="{!Myclaims}" var="claim">

You have a couple options in my mind to address this, but they all have drawbacks.
  1. Use the standardset controller (https://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm) and introduce pagination functionality.  After all, nobody is going to want to scroll through thousands of records.  The issue here is that the SSC or Standard Set Controller only allows 10,000 records, which it sounds like you're very close to.
  2. Nest iterators.  You'll essentially create a list of lists in your controller, and then use nested <apex:repeat> elements.  You may be able to get this to work with nesting apex:pageBlockTable elements, but I doubt it.
  3. Another option is to look at the particular user that's running the query, and see if you can't adjust the query and your sharing model to only return valid records, but that's more of a business requirement analysis
  4. Lastly, you could look at a series of javascript / remoteaction calls to achieve a large amount of records.  You could do this with frameworks like Angular with its datatables for instance.

logontokartiklogontokartik
Ok. Its kind of hard for me to identify which list is exceeding the limit, is it possible for you to reproduce the error? If yes, can you pull the debug log and identify which line/list is having issue. 

Based on that I would take a look to see if it can be initialized before loading or if it can be made transient.