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

Governor limits script statements?

what does the limit for script statements mean can anyone give me example how would end up in this limit seems abit funny as i have some very long code :)       :)       :)
Mostly, it prevents obvious programming flaws that the system might not be able to check at compile time. For example, say there is a small program logic like follows:

for(Integer i=0;i<10;i++)
 for(Integer j=0;i<10;j++)
  x[i][j] = i*j;

Everything looks okay at first, until you realize the inner loop will never terminate until a governor kicks in. If there were no limits, then this code would merrily run along forever, freezing that data node, or until the script crashed entirely from an overflow, etc. The governor prevents this code from executing billions of times until there's a integer overflow (billions? higher?), which could slow execution for other users on that node, consuming excessive processing time. This is a simple example, but a more complex example might be a loop that could either reset itself or continue in a randomly indefinate pattern that's impossible for a compiler to predict.

The limits are actually quite reasonable, and with the new async Apex coming up, you'll be able to run larger code with relaxed governors...

And for those that didn't catch it in the example above, the inner loop runs indefinitely since i is never incremented inside the second loop, but the conditional depends on i. Only the governor keeps this code from running forever.
ok so how would you break down the above example?
so doing something like this is bad?

   //Get a list of user assigned areas but not the current rep who has sold.
List<Portal_Assignment__c> allocList = SystemMethod.GetApprovedWorkingArea(sOwnerId);

//Lets first check if the area in the order is already assigned.
for(Portal_Assignment__c pFind : allocList)
allocAssigned = SystemMethod.ValidateString(pFind.approved_working_areas__c).split(',');

for(String getAssigned : allocAssigned)
if(getAssigned.equals(sAreaCode) || getAssigned.equals(sPostCode))
alreadyAssigned = true;
inArea = false;
winner = false;
System.debug('### AREA ALREADY OWNED BY ###: ' +;