+ Start a Discussion

List Object needs to be filtered. ASAP HELP!



I have a problem with a class.  I have create a list object of all the projects that fit a criteria.  Then i am looping through that list to build some report data.


Within this loop, I have 1 SOQL select statement that is grabbing all associated schedules for the project that is current in the loop.  This SOQL statement is just returning those values into a list object.


I am hitting that 101 SOQL max.  Is there anyway to filter down a List object?  Figure I can move the one SOQL statement out of the loop, but I still need to filter it down to get the totals i need for the report?


Any help would be great,  I am really in need of a solution on this one fast.




--Todd Kruse 

Park Walker (TAGL)Park Walker (TAGL)

Can you rework the SOQL so that it grabs the schedules in the same query? Another option would be to run a separate query to build a map of the schedule objects (ID, Object) and then run through your loop referencing the map instead of running a query.




Thanks for the reply.  What I am seeing, is that there are a minimum of 5000 records that need to be filtered.


I tried to create a list of schedules, but that blew up big time.  So I don't think a map would work since that can only hold 1000 records.


--Todd Kruse 


here are the lists I am trying to work with:


List<SFDC_Projects__c> allProjects = [SELECT Id,name, isDeleted, Project_Stage__c, Opportunity__c

                                                FROM SFDC_Projects__c 

                                                WHERE Project_Stage__c = 'Projected'

                                                OR Project_Stage__c = 'Booked' 

                                                Order By Project_Stage__c ASC, name Desc];


       List<SFDC_Schedule__c> allSchedules = [Select id, name, Assigned_Name__c, ServiceDate__c, Total__c, Project__c

From SFDC_Schedule__c 

Where ServiceDate__c >: startDate

And ServiceDate__c <: endDate

And Project__c <> null

Order By Assigned_Name__c, ServiceDate__c];



schedules are a child record to projects. so I am not sure how I can rework the queries.




--Todd Kruse