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
subaasubaa 

How to fix Too many script statements error: 200001

Hi,

 

We got a requirement to create VF page with four tables and each table may consist of 100+ records. It was requested to sort the table records using the distinct column header in each table. We wrote a sort method using bubble sort algorithm.

 

It is working perfectly for tables with less than of 100 records. But throws 'Too many script statements: 200001' error for tables with 120+ records. Especially, it throws an error when I perform sort function for descending order.

 

It seems that script statements count reset every time, when an action performed. But, it throws error, when I perform the sort function again for the same table.

 

Can anyone help me to fix this issue?

 

Regards,

SuBaa

Jake GmerekJake Gmerek

My thoughts on your issue.

 

Bubble sort is too ineffiecient for Apex.  What you need to do is requery your records with a different sort order each time that the sort order changes.  Then rerender your page with the new data in the proper sort order.

 

Another thing that you could try if you want to continue using bubble sort is to move the sort out of the controller to a separate public class.  Each sort should then be a seperate execution and possibly avoid that limit.  but if the number of records increases you may be back in the same boat. 

 

Hope it helps.

Rahul SharmaRahul Sharma

Hi subaa, try to optimize your code with use of minimum variables and loopings.

subaasubaa

Jake,

 

I had thought of rerendering predefined order of records while performing appropirate action. But I worried about that table records may get updated dynamically, which tends to resize the record count.

 

However, I haven't put more light on this approach. Let me try this once and get back to you with result. Thanks.

 

Regards,

SuBaa

Starz26Starz26

Check datatables.net

 

Not sure if it will meet your use case but it will do all of this client side once populated with the data.