Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Re: Too many Script lines:
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Too many Script lines:
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-02-2013 12:28 PM
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: Trigger.new){
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: Trigger.new){
for(id A1 : a.keyset() ){
account A2 = a. get(A1);
if(A2.JDE_Customer__c == h.JDE_Customer__c ){
// h.ParentId = A2.id;
try
{
h.ParentId = A2.Id;
//system.debug('Account = ' + a);
}
catch (Exception e)
{
system.debug('No Account Record ---- ' + e);
}
// system.debug('Accounts with Parents = ' + h);
listtoupdate.add(h);
}
}
}
}
Re: Too many Script lines:
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-02-2013 02:42 PM
Max
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: http://developer.force.com/cookbook/recipe/control
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)

