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

Too many Script lines:

The following code is producing the above error message. 


What am I doing wrong with this?


trigger GetParentBulked onAccount (beforeinsert, beforeupdate) {

list <Account> listtoupdate = newlist<Account>();       



// For loop to iterate through all the queried Sales History records



list<string> JDE = newlist<string>();      

for (Account  h1:{     

JDE.add(h1.Parent_Account_JDE__c);  } 

//system.debug('JDE Cust = ' + JDE);      

Map<id,Account> a = newmap<id, account>([Select Id,Name,JDE_Customer__c,Parent_Account_JDE__c fromAccountwhere JDE_Customer__c in: JDE]) ;

// system.debug(' Account Map = ' + a); 

for(Account h:{       

for(id A1 : a.keyset() ){          

account A2 = a. get(A1);           

if(A2.JDE_Customer__c == h.JDE_Customer__c ){              


// h.ParentId =;    



h.ParentId = A2.Id;              

//system.debug('Account = ' + a); 


catch (Exception e)     


system.debug('No Account Record ---- ' + e);     


// system.debug('Accounts with Parents = ' + h);                 










You are trying to build (new) Account records to insert in a before trigger on Account?


Not a good idea; this creates recursion issues -- instead, you should use 'after' triggers to related SObject updates - plus, you may need to use a static variable to avoid firing the before triggers, if any, on the Accounts you newly insert.


See recipe: 


As an additional debugging tip -- use the Limits system class to return  the # of script statements executed to date at various points in your code -- See Limits.getScriptStatements() --  


In geenral - too many script statements can be caused by:


* recursive triggers

* for loops executed within for loops within for loops

* too much logic complexity when applied to a single record multiplied by 200 (typical batch size)