0

I have an issue here, where i need to populate geography__c list on vf page. I am getting the below error . I can't use Limit 1000 as i need to display all the records in vf page. Is there any workaround for this issue.

Collection size 33,046 exceeds maximum size of 1,000

Vf Page -

<apex:actionregion >
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="{!$ObjectType.RFP__c.Fields.Country__c.Label}" style="width:87%; float:right;height:0px;font-weight:bold;font-family:Arial;font-size:11px;color:#2F4F4F;"/>

                        <apex:outputPanel id="countries" layout="block"  styleClass="requiredInput" style="width:82%; float:right;">
                            <apex:outputPanel id="countr" layout="block"  styleClass="requiredBlock"/>
                            <apex:selectList value="{!discountScheduleID}" size="1" styleClass=" chzn-select" >
                                <apex:actionSupport event="onchange" action="{!FindAllName}" rerender="geographies" oncomplete="renderChosen()" />
                                <apex:selectOptions value="{!dept}" />
                            </apex:selectList> 
                        </apex:outputPanel>

                    </apex:pageBlockSectionItem>

                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="{!$ObjectType.RFP__c.Fields.Type__c.Label}" style="width:87%; float:right;height:5px;font-weight:bold;font-family:Arial;font-size:11px;color:#2F4F4F;"/>

                        <apex:outputPanel id="type" layout="block"  styleClass="requiredInput" style="width:82%; float:right;">
                            <apex:outputPanel id="type1" layout="block"  styleClass="requiredBlock"/>
                            <apex:selectList value="{!TypeID}" size="1" styleClass=" chzn-select" >

                                <apex:selectOptions value="{!Type}" />
                            </apex:selectList> 
                        </apex:outputPanel>

                    </apex:pageBlockSectionItem>


                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="{!$ObjectType.RFP__c.Fields.Geography__c.Label}"  style="width:87%; float:right;height:8px;font-weight:bold;font-family:Arial;font-size:11px;color:#2F4F4F;"/>
                        <apex:outputPanel id="geographies" layout="block"  styleClass="requiredInput" style="width:82%; float:right;">
                            <apex:outputPanel id="geos" layout="block"  styleClass="requiredBlock"/>

                            <apex:selectList value="{!selectedGeographyIds }" multiselect="true" id="selectedGeographies" styleClass="fullWidth chzn-select" >

                                <apex:selectOptions value="{!AllName}" id="movieTextBox"></apex:selectOptions>

                            </apex:selectList>

                            <apex:outputPanel layout="block" styleClass="errorMsg" >
                                <apex:outputText value="{!errorMap['selectedGeographies']}" 
                                                 escape="false" rendered="{!errorMap['selectedGeographies'] != ''}" />
                            </apex:outputPanel>
                        </apex:outputPanel>
                    </apex:pageBlockSectionItem>
                </apex:actionregion> 

Apex Class -

public void FindAllName()
    {
        system.debug('@@@@@@ Entered');
        AllName= new List<SelectOption>();
        AllName= getName();
    }  

    public List<ID> holdData(){

        List<ID> rfpGeographiesToInsert = new List<ID>();
        for (ID selectedGeographyId : selectedGeographyIds) {
            rfpGeographiesToInsert.add(selectedGeographyId);

            system.debug('#############' +  rfpGeographiesToInsert);    
        }
        return rfpGeographiesToInsert;
    } 


    public List<SelectOption> getName()
    {


        Set<String> sProj = new Set<String>();
        List<Geography__c > tohold = new List<Geography__c >();

        List<ID> lst = new List<ID>(); 
        lst = holdData();
        system.debug('@@@@@@' + lst);
        if(discountScheduleID != null )
        {
            system.debug('1111111');   
            if(lst.size()==0)
            {
                system.debug('2222222');  
                for(Geography__c Proj  :[select Id, Canonical_Name__c, Type__c from Geography__c where status__c = 'active' AND Country__c =: discountScheduleID AND Type__c =: TypeID order by Canonical_Name__c] )
                {
                    system.debug('3333333'); 
                    options.add(new SelectOption(Proj.ID,Proj.Canonical_Name__c));
                    //strGeographix += Proj.Canonical_Name__c + ', ';
                    //errorMap.put('selectedGeographies',Proj.Canonical_Name__c);

                }
            }
            else
            {options.clear();

             for(Geography__c Proj  :[select Id, Canonical_Name__c, Type__c from Geography__c where status__c = 'active' AND Country__c =: discountScheduleID   and Id not in:lst order by Canonical_Name__c] )
             {
                 system.debug('4444444');
                 options.add(new SelectOption(Proj.ID,Proj.Canonical_Name__c));
                 //strGeographix += Proj.Canonical_Name__c + ', ';
                 // errorMap.put('selectedGeographies',Proj.Canonical_Name__c);

             }

             for(Geography__c Proj1  :[select Id, Canonical_Name__c, Type__c from Geography__c where status__c = 'active'  AND Id in:lst order by Canonical_Name__c])
             {
                 options.add(new SelectOption(Proj1.ID,Proj1.Canonical_Name__c));

             }

            }
        }        
        return options;

    }
}

Regards

9
  • It is unclear from looking at your code what the issue is. Can you specify the name of the list that has 33,046 records so that we can see where in the VisualForce page the issue is happening.
    – BarCotter
    Commented Oct 9, 2015 at 9:07
  • for(Geography__c Proj :[select Id, Canonical_Name__c, Type__c from Geography__c where status__c = 'active' AND Country__c =: discountScheduleID AND Type__c =: TypeID order by Canonical_Name__c] ) /////////// Line is holding the 33046 records... Commented Oct 9, 2015 at 9:10
  • The error is coming from the Visualforce page, where is that list being used in the vf page?
    – BarCotter
    Commented Oct 9, 2015 at 9:13
  • <apex:selectOptions value="{!AllName}" id="movieTextBox"></apex:selectOptions>....////// is the list where it is giving error... Commented Oct 9, 2015 at 9:18
  • 1
    Check out following link - salesforce.stackexchange.com/questions/5018/…
    – MIX DML
    Commented Oct 9, 2015 at 9:22

3 Answers 3

3

You are trying to display 33,046 values in a picklist/drop down list I think. I don't think that is a very wise idea even from a usability point of view.

Either try to break the picklist up by geographies, or use a search like feature to fetch the required values.

2

Try making Visualforce Page read only if it is feasible for you by using the attribute readOnly="true". The page will be processed in read only mode and you might not hit the limit.

0

Try one of the following:

  1. Create a List that will hold another List of Select Options, limit each internal list to hold upto 1000 records. Then use an apex repeat for displaying the Select options. This way you won't hit the limit.
  2. Fetch the list option values inside javascript by serializing it into json. Parse the json into javascript and dynamically create html select list and append it to your vf page. But this way you will have to manually update/insert records through remoting if required.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .