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
knicholsknichols 

dynamic soql in for loop

I can't do direct assignment in my query because it returns more than 1000 rows, but I can't figure out how to query in a for loop.  Normally it would look something like this

 

for (List<Account> accts : [SELECT id, name FROM account WHERE name LIKE 'Acme']) { // Your code here update accts; }

 

 That's static sql...how would I pass a string that's being built based on filters selected in a VF page?  We have a products page and they can select multiple filters & values and then query products.  I can't figure out how to pass the string of SOQL that I built to a for loop(like above).  Help!!!

 

 

HarmpieHarmpie

Did you try

 

 

for (List<Account> accts : Database.query(String query)) { // Your code here update accts; }

 

 

 

knicholsknichols
So I guess the problem is I have more than 1000 products.  I'm not real sure how to solve this.  Pagination?  Maybe?
Venkat PolisettVenkat Polisett

I think you are talking about a visualforce page. If so, use Listcontroller to display.

 

HariPHariP
I had similar request to count no.of records between given date range. Object has million records and around 195k records for given date range. I just need to get the total number. I tried countyQuery, didn't work. I tried for loop logic in this thread and it is still giving the 500001 records error.

Anyone has alternate solutions, please suggest.

Thanks