+ Start a Discussion
Jim BoudreauxJim Boudreaux 

200001 Script Statements, Oh My!

I solved my SOQL Limit problem by looping through the results of one SOQL query.

 

Now I am running against a Script Statement Limit. 

 

How should I go about optimizing my code to avoid this Limit? 

lvivaninlvivanin

Earlier I ran the same problem and I followed following way to fix the problem

 

- commented all the System.debug statements in my code

used break; in my for loop wherever appropriate

- revised my class method code to make shorter

- decreased the batch size for the bulk import

- called the class/methods (for example method related to do some calculations) out of the for loop, if it is   possible

-  merged related triggers to a single object to single trigger

 

 

Jim BoudreauxJim Boudreaux
are the statements totaled for all referenced classes? By this I mean, if I took one of my methods and took it out of my controller, and put it in a class that I reference from my controller, would I still hit the limit?
lvivaninlvivanin

in my experience - YES

 

Jim BoudreauxJim Boudreaux

is there a way to break code up into blocks in a way that the governor limits apply to each block?

 

My problem is this:

 

I have a custom object that represents a building. Each building has a related list of custom objects that represent floors.

So each building has some floors.

Further I have a custom object that represents a device on a floor in a building.

 

My controller gets a list of all the floors in a building and a list of devices in a building.

 

I run into the Script Statement limit when I loop through all the floors and for each floor I loop through the devices and find the devices that are on that floor.

 

This is fine for most buildings, but I have a 40 story building that is breaking my code. I need to come up with a more robust and scaleable way to do this.