2

I have a below pagesection and apex class method where i am trying to populate geography.

The issue is there is 86840 records in Geography__c objects. Due to which the vf page is not opening.

I can't use any where or limit clause as we have to populate all the geogeaphies.

Is there any other solution to do this.

Too many query rows: 50001 



<apex:pageBlockSectionItem >
                    <apex:outputLabel value="{!$ObjectType.XXX__c.Fields.Geography__c.Label}" />
                    <apex:outputPanel id="geographies" layout="block"  styleClass="requiredInput">
                    <apex:outputPanel id="geos" layout="block"  styleClass="requiredBlock"/>
                        <apex:selectList id="selectedGeographies" multiselect="true" value="{!selectedGeographyIds}" 
                                styleClass="{!IF(TRIM(errorMap['selectedGeographies']) != '', 'error', '')} fullWidth chzn-select" size="1"> 
                            <apex:selectOptions value="{!allGeographies}"/>
                        </apex:selectList>
                        <apex:outputPanel layout="block" styleClass="errorMsg" >
                            <apex:outputText value="{!errorMap['selectedGeographies']}" 
                                escape="false" rendered="{!errorMap['selectedGeographies'] != ''}" />
                        </apex:outputPanel>
                    </apex:outputPanel>
</apex:pageBlockSectionItem>



public List<SelectOption> allGeographies {
        get {
            if (allGeographies == null) {
                allGeographies = new List<SelectOption>();
                for (Geography__c geography: [select Id, Name, Type__c from Geography__c order by Name]) {
                    allGeographies.add(new SelectOption(geography.Id, geography.name + 
                            (geography.Type__c != null && geography.Type__c != '' ? ' (' + geography.Type__c + ')' : '')));
                }                
            }
            return allGeographies;
        }
        private set;
    }               
3
  • could it be that the page block section item is querying all values for EACH page block?
    – James
    Sep 22, 2015 at 14:14
  • Is there a fixed number of types (They should be less then 100 of course)? If there is you can query for each type seperately then add them all together.
    – tugce
    Sep 22, 2015 at 14:16
  • I am asking the question from more of an implementation perspective. Why are you querying around 80,000 records. If the number or geography records increase then read-only mode will not suffice. I believe you should implement a typeahead functionality which predicts as user is typing using VF remoting. I am suggesting this because I see that it's a select list that means it has to be entered by a user and I as a user would really not skim over 80000 geographies to select one. If you have a different use case please share.
    – manjit5190
    Sep 22, 2015 at 15:59

1 Answer 1

9

in your VF page use readonly="true" as this will allow you to make queries with a 1 million row limit

The caveat is that NO DML can be performed

Normally, queries for a single Visualforce page request may not retrieve more than 50,000 rows. In read-only mode, this limit is relaxed to allow querying up to 1 million rows

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_readonly_context_pagelevel.htm

You must log in to answer this question.

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