+ Start a Discussion
freddyloufreddylou 

System.Exception: Too many script statements: 50001

Help.

 

I am trying to use the dataloader to bring in a list of external ids and parses a hexadecimal number into a binary one and then calculates which applications are turned on for each contact.

 

It is a simple trigger - but generates the following 50001 error.

 

I am not sure what testing means - so never did any type of testing????

 

all i did was make sure it worked in sandbox for one-off contacts then moved it over to production.and did a dataloader upsert of 246 names - the first 46 came in fine then the rest had this error message.

 

do I need to use the map everytime is that the problem - I copied some other code I saw posted and modified it do what I want???

 

It did partially work - so worst case could break the csv file up but that is suboptimal.

 

trigger UpdateAppsUsed on Contact (before insert, before update) {
 
    // create a set of all the unique contacts
    Set<id> Contacts = new Set<id>();
    for (Contact a : Trigger.new)
        Contacts.add(a.Id);  
 
    // query for all the User records for the unique userIds in the records
    // create a map for a lookup / hash table for the user info
    Map<id, contact> contact = new Map<id, Contact>([Select  Basket_Trader_On__c,
Market_Maker_On__c,
Spread_Trader_On__c,
Trade_Ripper_On__c,Time_Slicer_on__c,
Managed_Order_Admin_On__c,
Exempt_from_short_locate_id_On__c,
Order_Ticket_On__c,
Wave_Grid_On__c,
News_Viewer_On__c,Equity_Quote_Cube_On__c,
Option_Quote_Cube_On__c,
Quote_Grid_On__c,
Quote_Explorer_On__c,
Equity_Time_and_Sales_On__c,
Option_Time_and_Sales_On__c,
Instant_Messenger_On__c,
Allocator_On__c,
Instant_Messenger_Admin_On__c,Report_Trade_On__c,
Adjust_Position_On__c,
Order_Grid_On__c,
Position_Grid_On__c,
Percentage_Order_On__c,
Override_Give_Up_On__c,
Proprietary_Theoriticals_On__c,
Vol_Trader_On__c,
Override_CMTA_On__c,
Override_Account_Type_On__c,
EOP_Trader_On__c,
Sector_Viewer_On__c,
Manual_Liquidity_On__c,
Spread_Book_On__c,
Spread_Builder_On__c,
Facilition_Orders_On__c,
Instant_Messenger_Support_On__c,
HLOC_Chart_On__c,
Imbalance_Viewer_On__c,
Staged_Order_Ticket_On__c,
Crossing_Basket_On__c,
Override_Trading_Account_On__c,
Spread_Viewer_On__c,
Spread_Ticket_On__c,
clientparams__c,testbinary__c from Contact Where Id in :contacts]); 
 
    // iterate over the list of records being processed in the trigger and
    // set the color before being inserted or updated
    for (Contact a : Trigger.new)   
    {
    string buildbinary='';
    Integer i = 2;
 
 
    integer count = 18;
   
    do  {
            
    if (a.clientparams__c.substring(i,i+1) == '0') {
    buildbinary=buildbinary+'0000';
    } if (a.clientparams__c.substring(i,i+1) == '1'){
    buildbinary=buildbinary+'0001';
    } if (a.clientparams__c.substring(i,i+1) == '2'){
    buildbinary=buildbinary+'0010';
    } if (a.clientparams__c.substring(i,i+1) == '3'){
    buildbinary=buildbinary+'0011';
    } if (a.clientparams__c.substring(i,i+1) == '4'){
    buildbinary=buildbinary+'0100';
    } if (a.clientparams__c.substring(i,i+1) == '5'){
    buildbinary=buildbinary+'0101';
    } if (a.clientparams__c.substring(i,i+1) == '6'){
    buildbinary=buildbinary+'0110';
    } if (a.clientparams__c.substring(i,i+1) == '7'){
        buildbinary=buildbinary+'0111';
    } if (a.clientparams__c.substring(i,i+1) == '8'){
    buildbinary=buildbinary+'1000';    } if
    (a.clientparams__c.substring(i,i+1) == '9'){
    buildbinary=buildbinary+'1001';
    } if (a.clientparams__c.substring(i,i+1) == 'A'){
    buildbinary=buildbinary+'1010';
      } if (a.clientparams__c.substring(i,i+1) == 'B'){
    buildbinary=buildbinary+'1011';
        } if (a.clientparams__c.substring(i,i+1) == 'C'){
    buildbinary=buildbinary+'1100';
        } if (a.clientparams__c.substring(i,i+1) == 'D'){
    buildbinary=buildbinary+'1101';
    } if (a.clientparams__c.substring(i,i+1) == 'E'){
    buildbinary=buildbinary+'1110';
    } if (a.clientparams__c.substring(i,i+1) == 'F'){
    buildbinary=buildbinary+'1111';    }
    i++;  system.debug(i);
    } while (i<count);
    integer s=64;
 if (buildbinary.substring(s-3,s-2)=='1')    { a.Basket_Trader_On__c=true;   }
if (buildbinary.substring(s-4,s-3)=='1')    { a.Market_Maker_On__c=true;   }
if (buildbinary.substring(s-5,s-4)=='1')    { a.Spread_Trader_On__c=true;   }
if (buildbinary.substring(s-6,s-5)=='1')    { a.Trade_Ripper_On__c=true;   }
if (buildbinary.substring(s-7,s-6)=='1')    { a.Time_Slicer_on__c=true;   }
if (buildbinary.substring(s-8,s-7)=='1')    { a.Managed_Order_Admin_On__c=true;   }
if (buildbinary.substring(s-9,s-8)=='1')    { a.Exempt_from_short_locate_id_On__c=true;   }
if (buildbinary.substring(s-10,s-9)=='1')    { a.Order_Ticket_On__c=true;   }
if (buildbinary.substring(s-11,s-10)=='1')    { a.Wave_Grid_On__c=true;   }
if (buildbinary.substring(s-12,s-11)=='1')    { a.News_Viewer_On__c=true;   }
if (buildbinary.substring(s-13,s-12)=='1')    { a.Equity_Quote_Cube_On__c=true;   }
if (buildbinary.substring(s-14,s-13)=='1')    { a.Option_Quote_Cube_On__c=true;   }
if (buildbinary.substring(s-15,s-14)=='1')    { a.Quote_Grid_On__c=true;   }
if (buildbinary.substring(s-16,s-15)=='1')    { a.Quote_Explorer_On__c=true;   }
if (buildbinary.substring(s-17,s-16)=='1')    { a.Equity_Time_and_Sales_On__c=true;   }
if (buildbinary.substring(s-18,s-17)=='1')    { a.Option_Time_and_Sales_On__c=true;   }
if (buildbinary.substring(s-26,s-25)=='1')    { a.Instant_Messenger_On__c=true;   }
if (buildbinary.substring(s-27,s-26)=='1')    { a.Allocator_On__c=true;   }
if (buildbinary.substring(s-28,s-27)=='1')    { a.Instant_Messenger_Admin_On__c=true;   }
if (buildbinary.substring(s-29,s-28)=='1')    { a.Report_Trade_On__c=true;   }
if (buildbinary.substring(s-30,s-29)=='1')    { a.Adjust_Position_On__c=true;   }
if (buildbinary.substring(s-31,s-30)=='1')    { a.Order_Grid_On__c=true;   }
if (buildbinary.substring(s-32,s-31)=='1')    { a.Position_Grid_On__c=true;   }
if (buildbinary.substring(s-33,s-32)=='1')    { a.Percentage_Order_On__c=true;   }
if (buildbinary.substring(s-34,s-33)=='1')    { a.Override_Give_Up_On__c=true;   }
if (buildbinary.substring(s-35,s-34)=='1')    { a.Proprietary_Theoriticals_On__c=true;   }
if (buildbinary.substring(s-36,s-35)=='1')    { a.Vol_Trader_On__c=true;   }
if (buildbinary.substring(s-37,s-36)=='1')    { a.Override_CMTA_On__c=true;   }
if (buildbinary.substring(s-38,s-37)=='1')    { a.Override_Account_Type_On__c=true;   }
if (buildbinary.substring(s-39,s-38)=='1')    { a.EOP_Trader_On__c=true;   }
if (buildbinary.substring(s-40,s-39)=='1')    { a.Sector_Viewer_On__c=true;   }
if (buildbinary.substring(s-41,s-40)=='1')    { a.Manual_Liquidity_On__c=true;   }
if (buildbinary.substring(s-42,s-41)=='1')    { a.Spread_Book_On__c=true;   }
if (buildbinary.substring(s-43,s-42)=='1')    { a.Spread_Builder_On__c=true;   }
if (buildbinary.substring(s-44,s-43)=='1')    { a.Facilition_Orders_On__c=true;   }
if (buildbinary.substring(s-45,s-44)=='1')    { a.Instant_Messenger_Support_On__c=true;   }
if (buildbinary.substring(s-46,s-45)=='1')    { a.HLOC_Chart_On__c=true;   }
if (buildbinary.substring(s-47,s-46)=='1')    { a.Imbalance_Viewer_On__c=true;   }
if (buildbinary.substring(s-48,s-47)=='1')    { a.Staged_Order_Ticket_On__c=true;   }
if (buildbinary.substring(s-49,s-48)=='1')    { a.Crossing_Basket_On__c=true;   }
if (buildbinary.substring(s-50,s-49)=='1')    { a.Override_Trading_Account_On__c=true;   }
if (buildbinary.substring(s-51,s-50)=='1')    { a.Spread_Viewer_On__c=true;   }
if (buildbinary.substring(s-52,s-51)=='1')    { a.Spread_Ticket_On__c=true;   }


   
  
  
    a.testbinary__c = buildbinary;
    }
 }

 

 

 

 

Shilpa_SFShilpa_SF

Hi,

 

    Here you are running a loop in trigger.new, might be this is causing governor limits to hit .Take all the contacts and loop throgh the list .