+ Start a Discussion
Carter85Carter85 

Strange List Size Error

I'm working in our sandbox currently on this method:
public PageReference proceed(){
        DEALER = true;
        if((vin != null && vin != '')){
            if(vin.containswhitespace()){
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Your VIN # entry contains a blank space, which may happen during copy and pasting from a different source, please check entry and try again.'));
                return null;
                }
            qry = 'SELECT ID, Vin_Number__c, Insurer__r.Name, Contract_Status__c, Vehicle_Make__c, Vehicle_Model__c, Vehicle_Year__c, Name, Benefits_Options__c, Batch__r.Product_Group_Name__c, Policy_Type__c, Contract_Number__c, Term__c, Class__c, Effective_Date__c, Expiration_Date__c FROM MG_Contract_Holder__c WHERE (Vin_Number__c =:vin) AND Batch__r.Product_Group__r.Service_Contract__c = false';    
            searchCreate();
        if(contractList.size() > 0){
            CONS = true;
            searchHistory();
            RETURNDEALER = false;
            return page.CM_WebClaimStep1;
            }
        else{
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'No contract found matching the information you entered, check entry and try again.'));
            return null;    
            }
            }
        else{
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please make sure the VIN Number field is filled in before searching.'));
            return null;
            }
            return null;
            }

public void searchCreate(){
        contractList = new List<ContractWrapper>();
            for(MG_Contract_Holder__c c : database.query(qry)){
                    if(c.Insurer__r.Name == 'NSD'){
                        NSD = true;
                        }
                    contractList.add(new contractWrapper(c));
                    }
                }
And I keep getting this error message when I execute the search: Collection size 2,327 exceeds maximum size of 1,000
I know from looking at other people's posts who have dealt with this error message is that it means I'm trying to populate a list on a VF page with more than 1,000 rows, except the thing is in this case I'm not trying to do that at all.  The sandbox I'm working in at the moment is only a partial data one and there is literally only one record which should be returned for this query based on the criteria.  And the whole process that this is contained in is working fine in production, I was only testing out an unrelated change which we'll be pushing out soon but I keep running up against this.  Does anyone have any thoughts on what may be causing this?
Rajiv Bhatt 16Rajiv Bhatt 16
not sure about this but does limiting the query size to 1000 help?
Carter85Carter85
I tried adding a Limit statement to the query but still received the same error unfortunately.
Pankaj_GanwaniPankaj_Ganwani
Hi,

Can you please put system.debug('==============='+contractList.size()) at the end of the function to check how many records are coming in?
Carter85Carter85
The debug statment shows the size to be 1, which I what I've been expecting, making the continued error all the more puzzling.
Thiyagarajan Selvaraj (SFDC Developer)Thiyagarajan Selvaraj (SFDC Developer)
VisualForce has its own specific limits.
A set-oriented standard controller can operate on a maximum of 2000 rows.
Collections referenced in other ways from VF pages have a maximum of 1000 rows.

Two options you have : 

1. use pagination (if the page is not read only)
2. set readonly="true" on apex:page (if the page is read only)

Choose the best one depends on your use case. 
Carter85Carter85
I found the error, it was actually related to a different table which populated based on this and another search statment and should not have been having the trouble it was but, because this was in our partial data sandbox a lot of things weren't hitting the filters like they do in production because the info which was being filtered had been removed and it was causing an overload to the list that way.