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

Need help with govenor limit, too many query rows: 1285



I am still learning how to not reach the limits, can you see what I am doing wrong here?



public void describeCase() { Schema.DescribeSObjectResult caseObj = Case.sObjectType.getDescribe(); Map<String, Schema.SObjectField> caseObjFields = caseObj.fields.getMap(); string caseSOQL = 'Select '; for (String fieldName : caseObjFields.keySet()){caseSOQL += fieldName + ',';} caseSOQL = caseSOQL.substring(0,caseSOQL.length()-1); caseSOQL += ' From Case where Project__c = :o limit 1000'; Case[] caseQuery; caseQuery = Database.query(caseSOQL); for(Case c : caseQuery){caseList.add( c.Clone(false,true));} for(Case c :caseList) { wrap w = new wrap(); w.caseLine=c; w.selected=true; caseedititems.add(w); } editIndex(); }



Best approach to circumvent this limit would be an approach like this:


for(Object[] objectList : [SELECT ..... FROM Object]) { for(Object o : objectList) { // handle single objects here } }





Hello Harmpie ,


Thank you, can you help me understand a little more?



This will have a limit of 1000 records ? If so how do I get all records, do I need to write something that returns batches under the limit, and in the UI allow the user to return another batch again and again, so its a way they could get to them all but no matter what I cannot display all in one list right?



for(Object[] objectList : [SELECT ..... FROM Object]) { for(Object o : objectList) { // handle single objects here }}





To better understand, some question from me:


What's the context of this code? Is it used by a trigger, by a Visual Force page? Do you need to present records on screen (VF) or is there no UI involved at all? What are you trying to do exactly?


I am facing a similar problem with Database.Query(queryString);


Below piece of code is in a VF page extension controller. 



String queryString = 'Select Id,Name from Product2 where Name='+conditionalName; for(List<Product2> prodList : Database.Query(queryString)) {// Transaction logicSystem.debug('List Size : '+ prodList.size()); // output is 'List Size : 200'}

Now when this piece of code executes from a Test Method system throws 'System.Exception: Too many query rows: 1001' error. I tried to append a limit statement to my code but that effects the output of my VF page. 


Thanks in advance,